How can I update a single line text field using automation with comma separated values?

keerthi
Contributor
February 7, 2024

Here is the automation setup which updates a Customer ID field based on customer names using a lookup table:

aut.png

 

The field 'Customer(s)' is a multi-select list and could contain one or more customer names. 

The Customer ID field is a single line text field.

I'm trying to append the Customer ID field with the IDs separated by comma. Any advise is appreciated.

Thank you.

2 answers

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2024

Hi @keerthi 

For your scenario you describe:

  • a multiple-select custom field called Customer(s) contains customer names
  • a text field called Customer ID, intended to hold a CSV list of customer id values for the selected customers in the Customer(s) field

 

The only way to perform that translation (name to id) to then load the CSV list is with inline replacements, such as this assuming customer names of ABC and DEF with associated ids of 123 and 456.

{{issue.Customer(s).value.join(",").replace("ABC","123").replace("DEF","456")}}

Repeating the replacements for each customer name / id pairs.  That is going to prone to errors and maintenance-heavy to support.

Perhaps a better approach would be to combine the fields, and parse out the things you need.  For example, the values in the multiple select list could be:

  • ABC (123)
  • DEF (456)
  • ...

(Yes, I know this combines two pieces of information in one field, for the DBAs taking note :^)  When the names (or ids) are needed elsewhere in rules, text functions can extract them.

 

More details:

The lookup table action seems like it would be a good approach for this scenario, but rule iterators cannot access information from outside.  That is, this cannot work...

{{#issue.Customer(s)}}{{customerId.get(value)}}{{^last}},{{/}}{{/}}

The lookup table cannot be seen once inside of the iterator's scope.

 

Kind regards,
Bill

keerthi
Contributor
February 9, 2024

Hi Bill, 

Your solution to combine strings would be the solution I will go for.

Could you help me figure out how to extract a substring from the list item. I could find documentation on list functions and text functions but not sure how to combine the two.

 

For context, I've updated the 'Customer(s)' values to now include Name - ID. 

I tried logging the following: {{issue.Customer(s).substringAfter(" - ")}}

 

But it returns a blank.

 

Thanks for your help!

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2024

You almost have it; the missing part is to select the values for the field.

{{issue.Customer(s).value.substringAfter(" - ")}}

This will produce a list of values.

As you wanted to put these into a text field as CSV, one addition would be this:

{{issue.Customer(s).value.substringAfter(" - ").trim().join(",")}}

That will removing any additional whitespace characters, and then join the list into a single text string.

 

If that does not work, the smart value "Customers(s)" may be incorrect for the field.

Smart values are name, spacing, and case-sensitive.  And often the smart value does not match the displayed field name on the issue views.  These steps can help to identify the correct smart value (and custom field id) for the field.

The essential steps are:

  • identify an issue which has your field(s)
  • call a REST API function with a browser to search for your issue:
https://<yourinstanceurl>/rest/api/2/issue/<issuekey>?expand=names
  • search on the page for your field, such as with CTRL-F
    • if you find the field, you will also find the smart value, custom field id, and structure / attributes it has
    • if you do not find the field, it may not be supported by automation rules

 

keerthi
Contributor
February 9, 2024

Thanks a million! That worked perfectly

Like Bill Sheboy likes this
1 vote
Derek Fields _RightStar_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2024

Use the "join" function of lists. The smart value would look like this:

{{issue.Customer(s).join(",")}}

See Jira smart values - lists | Cloud automation Cloud | Atlassian Support for more information

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events