Automation with temporary (trimmed) values not working
Asked by bozidar.ercegovac:

Here is my issue. I have set up automation that calls an API. This is how the body looks like

{ "firstName": "{{issue.customfield_10284}}", "lastName": "{{issue.customfield_10285}}", "displayName": "{{issue.customfield_10284}}", "name": "{{issue.customfield_10284}}", "oib": "{{issue.customfield_10265}}", "defaultAccount": { "accountCode": "{{issue.customfield_10247}}" }, "userTid": { "name": "{{issue.customfield_10274}}", "feeFixed": "{{issue.customfield_10278}}", "feePercentage": "{{issue.customfield_10279}}", "buyConfirmation": "{{issue.customfield_10369}}", "multipleScan": "{{issue.customfield_10372}}", "providerId": "{{issue.customfield_10260}}", "isKeksMerchant": true, "eventCategory": { "eventCategoryId": "{{issue.customfield_10280}}" } }, "skipPaymentInfo": true }  

The problem lies with providerId. Currently, 10260 is a multi select option, with each option consisting of key-value pairs, like "14 - String".  

What I need is just the numeric value. What I've tried to do was setting up a temporary trimmed value 10374, which is a free text format.

<br />

First, I have tried trimming 10260 to 10374 with different functions  

{ "fields": { "customfield_10374": "{{issue.customfield_10260.match("\^\\\\d+")}}" } }

{ "fields": { "customfield_10374": "{{issue.customfield_10260.substringBefore(' - ')}}" } }

{ "fields": { "customfield_10374": "{{issue.customfield_10260.split(' - ').first}}" } }

<br />

After that I tried replacing the

"providerId": "{{issue.customfield_10260}}

with

"providerId": "{{issue.customfield_10374}}"

in the API. I would just be getting response errors because it turns out that my temporary value was not being saved.  

As a control, I have set up comments in Jira issues:

Trimmed value is: {{issue.customfield_10374}}

Full value for (customfield_10260) is: {{issue.customfield_10260}}  

The first one returns null, the second one returns "14 - String". In happy path, I would get "14" for the first command.  
Not sure why the value is not being saved and even if this approach is doable.

<br />

I have also tried to trim the value directly in APi body with different commands, but In this case I am just getting errors

{ "firstName": "{{issue.customfield_10284}}", "lastName": "{{issue.customfield_10285}}", "displayName": "{{issue.customfield_10284}}", "name": "{{issue.customfield_10284}}", "oib": "{{issue.customfield_10265}}", "defaultAccount": { "accountCode": "{{issue.customfield_10247}}" }, "userTid": { "name": "{{issue.customfield_10274}}", "feeFixed": "{{issue.customfield_10278}}", "feePercentage": "{{issue.customfield_10279}}", "buyConfirmation": "{{issue.customfield_10369}}", "multipleScan": "{{issue.customfield_10372}}", "providerId": "{{issue.customfield_10260.match('\^\\\\d+')}}", "isKeksMerchant": true, "eventCategory": { "eventCategoryId": "{{issue.customfield_10280}}" } }, "skipPaymentInfo": false }  

Any tips are appreciated.  


Answers:
author: Bill Sheboy
body: Hi [@bozidar.ercegovac](/t5/user/viewprofilepage/user-id/5528014) -- Welcome to the Atlassian Community!

For selection custom fields, the selected value(s) uses the attribute *value*, like this:

```
{{issue.customfield_10260.value}}
```

Once you have that, your other attempts to parse out the number left-of-the-hyphen should work.

However...you also note this is a *multiple selection field*, and so that expression would produce a result, such as this:

```
14 - string, 15 - another string, 17 - one more string
```

But your "providerId" seems to be a single value. Is that correct?

Kind regards,  
Bill

comments: author: bozidar.ercegovac
body: 10260 is a multi select, has a drop down, all options are in format "14 - string" etc.

10374 is free text, which is supposed to be used for saving the trimmed value.  

So when I test with this mid step:

"Trimmed value is: {{issue.customfield_10374}}

Full value for (customfield_10260) is: {{issue.customfield_10260}}"  

I get, as a result  

"Trimmed value is:

Full value for (customfield_10260) is: 14 - String"  

The selected drop down value is selected OK, but the trimmed is NULL.


author: Bill Sheboy
body: What you describe does not match the behavior I see for multiple-select fields in Jira Cloud automation rules.

Please post the following to help diagnose this symptom:

* in which type of project this rule is defined: company-managed or team-managed
* if team-managed, where the custom field is defined: site admin (global) or only for the project
* an image of your complete automation rule (in one continuous image)
* images of the actions / conditions / branches where you are using that smart value expression
* an image of the audit log details, showing the rule execution

Thanks!


author: Joseph Chung Yin
body: [@bozidar.ercegovac](/t5/user/viewprofilepage/user-id/5528014) -

I agreed with what [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) suggested. To help you to debug, I don't know if you are using the automation audit log - where you can write to the log as an action where you can review what is showing in the audit log. At the same time, you can create a "local variable" to store the value that you are pulling from your custom field, then you should be able to work on the "local variable" to trim your content.

Here is the link on how to use the Audit Log for automation rule troubleshooting in case you don't already know -

<https://support.atlassian.com/cloud-automation/docs/debug-an-automation-rule/>

Here is the "Local Variable" concept for automation rule setup link -

<https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Create-variable-New-component/ba-p/1448118>

Please advise, so we can assist you further.

Best, Joseph Chung Yin

comments: author: bozidar.ercegovac
body: The audit log shows no errors, everything works "as intended" according to them. I have pasted this in other reply  

10260 is a multi select, has a drop down, all options are in format "14 - string" etc.

10374 is free text, which is supposed to be used for saving the trimmed value.  

So when I test with this mid step:

"Trimmed value is: {{issue.customfield_10374}}

Full value for (customfield_10260) is: {{issue.customfield_10260}}"  

I get, as a result  

"Trimmed value is:

Full value for (customfield_10260) is: 14 - String"  

The selected drop down value is selected OK, but the trimmed is NULL.


Tags: cloud

jira-service-management

jira-service-management-cloud