Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate and translate values into a separate field

sarah.wight October 23, 2022

Hi - I am very new to Jira. I am trying to create an automation that will update a field on my issue. I will attempt to explain, using generic capitalized field names:

In the NAME field, I want to concatenate values from the REGION, TYPE and DATE fields.

I want to reformat a value selected in the TYPE field and in the DATE field as part of the final concatenated value in the NAME field.

For example:

  • TYPE can have values Type A, Type B or Type C
    • Type A = A
    • Type B = B
    • Type C = C
  • DATE uses the calendar lookup and produces the value MM/DD/YYYY
    • Need YYYYMMDD

In the NAME field, I want to concatenate: REGION-TYPE-DATE

A final example of the value format in the NAME field would be: NAM-A-20221023

What syntax do I use in the NAME field to produce these results?

2 answers

1 accepted

1 vote
Answer accepted
Thuan_ Do Dang
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.
October 23, 2022

Hi @sarah.wight ,

You can try edit field action with smart values like below

{
"fields": {
"Your Field Name": "{{issue.your_region_field}}-{{issue.your_type_field.substringAfter(\"Type \")}}-{{issue.your_date_field.format(\"YYYYMMDD\")}}"
}

To find your field in smart value, access Filters > Advanced issue search > Switch to JQL (if you're in basic mode) type your field name.

If it contains cf[10xxx] then your field in smart value should be customfield_10xxx.

You can find more text field functions here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/

Date field functions here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/

Hope this helps!

sarah.wight October 24, 2022

Thanks @Thuan_ Do Dang - I'm doing something wrong but I don't know what. Here is my syntax:

{{issue.Region}}-{{issue.customfield_12258.substringBefore("-")}}-{{issue.startDate.format("YYYYMMDD")}}--{{issue.Summary}}

It is populating this:

GL----Summary value

It was very difficult to find the custom field ID - what you suggested did not show it. I had to Inspect the page and search for it that way. But I found it and changed to substringBefore (instead of After, as you showed, because my example was not exactly how I had each value formatted in reality).

I am not sure how to write the Smart Value for the system field "Start date". I have tried entering an underscore between the words, leaving a space, and putting them together as you see above but nothing is being produced.

Regardless, my attempt is only showing the Region and Summary field values. It is not populating the custom field and date values between those two.

What did I do wrong?

Thuan_ Do Dang
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.
October 24, 2022

Hi @sarah.wight ,

 

Because of your syntax inside "", if you have other ", it should be \" 

{{issue.Region}}-{{issue.customfield_12258.substringBefore(\"-\")}}-{{issue.startDate.format(\"YYYYMMDD\")}}--{{issue.Summary}}

Hope this helps!

sarah.wight October 25, 2022

Nope, this did not work. I have no idea why. I feel like there is just something simple missing here. The Region and Summary values are the only ones populating.

Is there anything else I can try or should I troubleshoot some other way?

Thuan_ Do Dang
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.
October 25, 2022

Hi @sarah.wight ,

I'm sorry for my mistake. Here is the updated syntax 

  • The right field name is 'Start date' instead of 'startDate'
  • The date format change from 'YYYYMMDD' to 'YYYYMMdd' while DD is day of year and dd is day of month.
  • Add '.value' after select list custom field to get that field value
{{issue.Region}}-{{issue.customfield_12258.value.substringBefore("-")}}-{{issue.Start date.format("YYYYMMdd")}}--{{issue.Summary}}

Hope this helps!

sarah.wight October 26, 2022

Hi @Thuan_ Do Dang - This has gotten me closer!

{{issue.Region}}-{{issue.customfield_12258.value.substringBefore("-")}}-{{issue.Start date.format("YYYYMMdd")}}--{{issue.Summary}}

Now produces:

GL-TD---My Show

I don't know what is wrong with the date field and/or format syntax but it just will not populate anything. In my research, I have found that this format of date is called "BASIC_ISO_DATE". How can I reference that? Anything else I can try to get the date in that format? Am I referencing a field that cannot be used int his way - Start date?

Thuan_ Do Dang
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.
October 27, 2022

Hi @sarah.wight ,

The syntax of date above is a right syntax, it works on my instance. However, we can try other way, using 'customfield_10xxx' instead of 'Start date'.

Please go to Settings icon next to your avatar > Issues > Custom fields > search your date field (make sure your date field type is Date picker or Date time picker) > click ... at the end of a field > select View field information/Edit field > look at your URL, you can see your custom field id there.

Hope this helps!

sarah.wight October 27, 2022

Hi @Thuan_ Do Dang & @Bill Sheboy - I found this article: https://community.atlassian.com/t5/Jira-Software-questions/What-is-the-smart-value-for-my-custom-start-date-field/qaq-p/1793650

...and viewed all of the fields on my issue to see if there was a custom field ID for the "Start date" field, which I had assumed (ah hah!) was a system field, not a custom field. Apparently, it is a custom field? Either that or every field actually has a custom ID????

Anywho, I found the custom field ID for "Start date", popped it in to my concatenated string, and after approximately 40 hours of researching, trial and error, headaches, complaining to my husband and colleagues, and working with you both: IT WORKED.

{{issue.Region}}-{{issue.customfield_12258.value.substringBefore("-")}}-{{issue.customfield_12007.format("YYYYMMdd")}}--{{issue.Summary}}

  • customfield_12258 = Campaign Type
  • customfield_12007 = Start date

Aside from the excessive development time spent on this, I would be happy with this final result save one small detail: "Region" is actually a custom field and I know that for a fact because I made it. So, for consistency's sake, why - WHY do I NOT need a custom field ID there, but I DO for Campaign Type and Start date? Please tell me there is a legitimate reason and I'm not just taking crazy pills. THANK YOU

Like # people like this
0 votes
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.
October 25, 2022

Hi @sarah.wight 

First thing, I am going to assume your fields are not actually named TYPE and DATE, as that could cause both confusion and potential problems for your site admin.  If those are the names, consider changing the names to better match their meaning.  I am also assuming that REGION and TYPE are single-select field types.

Next, for a question like this context is important; please consider posting an image of your complete rule as that will help the community see the same thing as what you are observing.

 

As you have described your use case, please try pasting this smart value into the edit for the NAME field.  There is no need to use the advanced JSON edit.

{{issue.REGION.value.concat("-").concat(issue.TYPE.value).concat("-").concat(issue.DATE.format("YYYYMMDD"))}}

After you paste it in, the smart value will appear below the field, and you can then select it to use in the edit action.

 

To learn more about the concat() function, please look here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#concat-String-str-

To learn about the date/time formatting, please look here: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#--

Kind regards,
Bill

sarah.wight October 26, 2022

Hi Bill - Thanks for sharing that information about concatenating and date formatting.

My main problem is the examples given on these pages do not paint an entire picture for someone who is not a developer by trade but needs to do some of this work. I'm not saying rewrite everything; I am saying a few small changes would have helped me a great deal. For example - in the examples:

  • Depict how and when to write syntax when referencing a custom field
    • Do we need to use the custom field's system name?
      • If so, show us how to get a custom field's system name - I read 3-4 different entries about how to do this and only ONE was successful - by going to an issue where the field is used and right-clicking, selecting inspect, hovering over the field, and finding where it says "customfield_xxx"
      • If not, then why have examples depicting the use of the custom field's system name? In my attempts to create the right syntax, I tried both the visible field name and the system name for my custom fields. For a one-word custom field name, it appears I don't need the system name! But for a 2-word custom field name I have to use the system name or it doesn't recognize the field I am referencing.
  • For a 2-word (or more) standard field, do you remove the space when you reference it? Do you lowercase the first letter and capitalize the 2nd (or 3rd, etc) letter(s)? Is this commonplace? I have no idea and most examples seem to use one-word standard fields.
  • Some of the functions do not clearly depict how you customize for your needs. Perhaps a written example: "I am trying to concatenate fields A and B into field C, and this is the syntax I used for that..."
  • Again, I am not a developer. I suspect other non-developers find themselves sifting through all of this knowledge, somewhat aimlessly, searching for help. How and where do we go for information on how to customize automations beyond the basic examples given?
    • My frustration led me to post a question here. I typically would not resort to this - I'd rather research until I fall off my chair from exhaustion. But my limited knowledge and unclear examples forced me to take this route.

 

Now back to my use case, which I didn't think I would have to post true details of. I get the "we need context" suggestion but I admit, I thought my question and need was simple. I didn't think I had to go that far. Here are all of the juicy details:

I have an automation, where upon an issue being created, I want to concatenate values from 4 different fields - some custom, some standard - into a separate custom field:

Screenshot_20221026_082849.png

Now here's the rub - for 2 of the 4 fields in my concatenation, I want to format the values. Here are all of the fields I want to concatenate:

  • Region (custom field with text in a picklist of values exactly how I want them to be written)
  • Campaign Type (custom field with text in a picklist of values. The only part of the text I want from the selected value appears before a "-"
  • Start date (standard field. I want the format of the value set here to be YYYYMMDD)
  • Summary (standard field. No change to format. I want the text exactly as it is written here)

The field I want to place this concatenation into is a custom field called "Campaign Name".

I won't confuse you with the 50 ways I've tried to write the syntax for this concatenation. The most I was able to produce was the Region and the Summary values, but none of the formatted values for the Campaign Type or Start date fields appear.

Can anyone, now with this context, tell me how to properly syntax the concatenation of these 4 fields?

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.
October 26, 2022

What happened when you tried the smart value expression I provided, as I believe that matches what you asked to do?

 

I can understand and empathize with your comments about the documentation for automation rules.  It continues to improve, and it still needs improvements.  When I find a particularly confusing documentation page, I select the "Provide feedback about this article" to give Atlassian feedback.

Regarding custom field names and the resulting smart values: as admins can change the names of fields as they wish, the spacing and capitalization can be impacted for the smart value.  This particularly happens when customers use non-alphanumeric characters in the field names.  When the field is supported, the custom field ID value should work if you are unable to determine the smart value based on the field name.

I also agree that for simple use cases, automation rules are straightforward to create and use.  For more complicated needs, often experimentation is required to get the syntax to work as desired.  I good approach is to create a simple rule in a test project, often writing to the audit log to confirm results.  Once your rule is ready then copy it to the desired project.

sarah.wight October 26, 2022

Hi Bill - When I used the smart value expression you provided, it gave me the region value and the type value, but not the date value.

Of course the type value was not the format I needed, but regardless the entire concatenation did not appear.

There must be something wrong with the way I am referencing the standard field "Start date" in the expression, because even without my preferred format for Start date, nothing is being returned. Does it need to be Start_date? Start_Date? startDate? Startdate? Something else entirely? It is not a custom field, so that is not a possibility.

But once I figure that out, how do I format the Start date as YYYYMMDD? Also known as BASIC_ISO_DATE, as I discovered. 

I appreciate all of the help I've received so far. See Thuan's responses below. His help has gotten me the furthest to my goal, with the Start date value and format missing there as well.

Like Bill Sheboy likes this
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.
October 27, 2022

Hi, Sarah!

Something I find helpful to build up a concatenated string like this is to first write the pieces, one by one, to the audit log.  When I get formatting correct, I then start combining them to confirm the results.

If you are using the built-in Start Date field, the smart value would be

{{issue.Start date.format("YYYYMMDD")}}

For the Campaign Type, you may need to pull that apart with the following.  Please adjust to match your field name's smart value.

{{issue.Campaign type.substringBefore("-").trim()}}

 

And I completely agree with you on the confusion for "when does a smart value work as the field name versus only the custom field id"?  I hypothesize there is something internally that collides with customer-chosen field names...they we (customers) cannot see that collision.  The only way to be certain is that how-to from Atlassian on calling the REST API to find the supported smart values.

And even then...not all custom fields work with all functions!  So when in doubt, write to the audit log first to confirm the pieces before rolling stuff up into a complex expression.

Kind regards,
Bill

Like sarah.wight likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events