Forums

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

parse string from a variable in automation

Ste404
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.
July 11, 2022

Hi there,

I am putting an automation in place that if the approver name is deleted from the field automation writes it back.

I am capturing the previous value of the approvers field using this  

{{fieldChange.from}}

The result gets stored in a variable.

The problem is the ID that is being stored is an object so it has [ ] around it.

I saw there is a .remove that can be used to remove a string from a field but not sure how to apply it to this automation.

I had this

{{PreviousValue.remove("[")}}  just to see if it would be removed as a log event but it spits out an error stating invalid JSON.

Maybe I am going about this incorrectly so would love to understand how this should be put together.

The ultimate goal is to edit the issue and update the approver field with the stored variable.

 

1 answer

1 accepted

3 votes
Answer accepted
Mark Segall
Community Champion
July 11, 2022

Hi @Ste404 and welcome to the community!

In this type of case, I typically capture the JSON as is in the variable and then create a second variable that performs the cleanup of the first variable then use the second variable in my subsequent conditions/actions.

Ste404
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.
July 11, 2022

hey @Mark Segall thanks for that, you answer means I was on the right track but I wasn't sure where to put the multiple lines in order to trim the previous variable.

I assumed I need these two lines

{{PreviousValue.remove("[")}}
{{PreviousValue.remove("]")}}

but in the 'Smart Value' line in create variable it gets entered as a single line.

I put those two items in side by side but it failed, do I need to wrap them in another set of brackets?

Mark Segall
Community Champion
July 11, 2022
  1. Your second variable should be against your first variable so it would look something like variable.remove("[") and then your third variable would key off of your second variable.
  2. You may be able to do this with only the second variable with something like this:
    1. {{YOURVARIABLE.match("\[(.*?)\]")}}
Like Ste404 likes this
Ste404
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.
July 11, 2022

ok that fixed the parsing, great info.

 

This is failing now, but will have a scratch around to see what I have mistyped.

{
"fields": {
"approvers" : [{ "id": "{{FixedPrevious}}" } ]
}
}

Ste404
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.
July 11, 2022

I was over complicating the last part, I just used the smart value directly to edit the Approvers field..  works a charm.

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