Forums

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

Jira Automation: how to copy value then remove everything except for numbers?

Chris Case December 28, 2023

I have a custom field that contains alpha, numeric, and special characters.

I need to copy the value to a diff custom field then trim out all values except for the numeric characters.

Right now I have it set to trigger when a value is added to the custom field. 

Then edit the issue and copy custom field 1 to custom field 2.  

I'm then using "Additional Fields to update the copied text to replace all characters except for the numeric.

The Copy function works but when I get to the step to modify the text I get the following error:


Error while rendering additional fields.
Failed to get value for issue.fields.customField_10124.replace('[^0-9]', '')
This is the Additional field data I'm using. 
{
"fields": {
"customfield_10124": "{{issue.fields.customField_10124.replace('[^0-9]', '')}}"
}
}
I've tried switching the target and source custom field numbers, and I've tried adding a Re-fetch issue data step but nothing seems to fix it.  Thanks for any help you can provide!

3 answers

2 accepted

4 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.
December 28, 2023

Hi @Chris Case 

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

The replace() function only finds / replace text expressions.  To use a regular expression please try using the replaceAll() function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#replaceAll-String-regex--String-replacement-

And please note: it is not documented for automation rules which parts of the Java spec for regular expressions are / are not supported.  I recommend trying simpler expressions first, writing the results to the audit log, and confirming they work as you expect before trying to edit the issue fields.

Kind regards,
Bill

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.
December 28, 2023

Thanks for the rule image, Chris.

I see you are trying to use single-quotes within the replaceAll() function, with that then nested within double-quotes for the JSON expression.  That will not work: those all need to be double-quotes within the smart value expression.

One work-around for that is to perform the replacement first, saving the value in a created variable.  Then use that created variable in the JSON for the advanced edit.

Chris Case December 29, 2023

Huzzah!  The combo of using the create variable and using double-quotes fixed it and it's now working :)

This is what I ended up with - using the Create variable function and replaceALL smart value (with double-quotes) then using that created variable to add to the other custom field.   Thank you for your help!

Screenshot 2023-12-29 at 1.16.00 PM.png

Screenshot 2023-12-29 at 1.16.07 PM.png

Like Bill Sheboy likes this
0 votes
Answer accepted
Joseph Chung Yin
Community Champion
December 28, 2023

@Chris Case -

Hi Chris:

Try this out in your automation -

Example -

my original string is "Jira Admin IT test 1 please ignore 235"

my smart value used is - "new value - {{issue.summary.replaceAll("[^0-9]","")}}"  and I just utilize the "Log action" action to write the output to the audit log.  The audit log shows the new value as - "new value - 1235"

Hope this helps.  BTW, it is a best practice to get your desired value to output it to audit log for debugging automation rule purpose - https://support.atlassian.com/cloud-automation/docs/debug-an-automation-rule/

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Technology Applications Team

Viasat Inc.

Chris Case December 28, 2023

Thank you both for your help.  First time posting to the community :) 

Here are the screenshots of the rule I've been trying to build out (I've removed the extra steps to refresh data. 

Note `customfield_10124` is the target where I'm trying to copy the numeric value to and `customfield_10085` is the source where the alphanumeric value is located.

I just tried again by switching to replaceAll but I don't think I'm using it correctly.  

Also tried generating a log action and I'm getting the same error (or looks like it's the same). 

For additional context the two custom fields are "Label" type fields if that's helpful or if either of you know if those are not supported.Screenshot 2023-12-28 at 4.46.22 PM.pngScreenshot 2023-12-28 at 4.46.42 PM.pngScreenshot 2023-12-28 at 4.48.31 PM.pngScreenshot 2023-12-28 at 4.49.48 PM.pngScreenshot 2023-12-28 at 4.49.34 PM.png

Joseph Chung Yin
Community Champion
December 29, 2023

@Chris Case -

Have you try to use double quote instead of single quote? 

Let me know of your findings.

Best, Joseph

Chris Case December 29, 2023

Yes thank you for your help!  The double quotes and using the variable was the key to get it to work. I added the automation I ended up with above for reference.

0 votes
Chris Case December 28, 2023

Updated to remove text -- meant to add as a reply

Suggest an answer

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

Atlassian Community Events