Not able to use String function with Smart Value in lookup object
Asked by Sarika Dalal:

Hi Team,

I got one requirement from customer for insight object, they have one Object Schema In that they are creating object they want once any object got created field **AssetID** value should be automatically increment by one in the last Object **AssetID**

Let's take one example here

**Object Key AssetID**

LAB-123 ABC001

LAB-124 ABC002

LAB-125 ABC003

So the field **AssetID**value should be automatically added, so I am using Automation in JSM

Here is the details about the configuration :

**When**: Object Created

**Then** : Lookup objects

insight query language is

objectType = TEST ORDER BY AssetIDD DESC

here **AssetIDD**is text field

Then : edit Object

Select field : AssetIDD

Value : {{lookupObjects.get(1).temp_Asset_ID.charAt(2)}}

++**ERROR:**++

##### [Edit Insight field attributes](https://avellino.atlassian.net/plugins/servlet/ac/com.codebarrel.addons.automation/cb-jira-automation-rules#!/rule/2591013/68320555) {#toc-hId-1986926613}

Error updating Object(s)  
Objects were skipped  
LAB-6858 (temp_Asset_ID = '')

So this is the configuration I have added but I can see all the text function is not working here and getting always empty value and in Automation audit log I can see error, I can achieve same requirement If I am using only number field but with text field no smart value function is working

following this document : [smart-values-text-fields](https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields)

Any suggestion why my text function are not working ?

Thanks,

Sarika Dalal


Answers:
author: Ignacio Pulgar
body: Hi [@Sarika Dalal](/t5/user/viewprofilepage/user-id/684113) ,

Please, try using getValue as suggested here:

<https://community.atlassian.com/t5/Jira-questions/Using-String-Manipulation-functions-on-Select-List-Fields-Jira/qaq-p/1477939>

Hope it helps.


author: Bill Sheboy
body: Hi [@Sarika Dalal](/t5/user/viewprofilepage/user-id/684113)

First thing, I do not have Jira Service Desk, so I will try to help based on what I see in your automation rule.

* Is temp_Asset_ID a defined field in that lookup, as it may not be present if it is returning as empty?
* For {{lookupObjects.get(1)... I believe this is trying to return the second item in the list, as these are 0-base indexed. Is that what you want? Otherwise if you want the first one, perhaps try: {{lookupObjects.first...
* Your AssetID values are of the format ABC001, and you are trying to access at charAt(2). According to the documentation, this one is 1-base indexed, so this may not be what you want. Consider writing the values to the audit log to confirm what is happening.
* And, as your AssetID values are alphanumeric, if you are trying to increment with a rule, wouldn't you need to split that value into the alpha and numeric parts, increment, and then concatenate the result?

Kind regards,  
Bill

comments: author: Sarika Dalal
body: Thank you for the response [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) .

let me add few more points here :-

when I am trying {{lookupObjects.get(1).temp_Asset_ID}} its giving me value of the field after that I am using function {{lookupObjects.get(1).temp_Asset_ID.charAt(2)}} that is not working. with charAt function I am just testing String functions.

Issue is all string functions is not working here and every time I am getting null response.

Your thought is correct about point 4 I am going to split number and text field value only and then I will do increment in number.

Regards,

Sarika Dalal


author: Bill Sheboy
body: You are using Cloud, correct? If so, perhaps do this in two steps to force the type conversion to string:

* create a variable and set the value to the temp_Asset_ID
* then perform the charAt() on the variable

I recall needing to do this for other fields which are dynamically generated before I could use them in expressions.


Tags: cloud

jira-service-management