JWT Copy a parsed text to a field : Checkbox

Marc Jason Mutuc
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.
June 28, 2018

I have a checkbox with the following options

Blue (BL)

Red (RD)

Magenta (MG)

Green (GN)

The output I want is BL,RD,MG,GN

So, I tried using this script:

findPatternIgnoreCase(%{19401},"BL|RD|MG|GN"

It is not working unfortunately. Help!!!

1 answer

1 accepted

1 vote
Answer accepted
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 28, 2018

Hi @Marc Jason Mutuc,

what kind of field type is your target field? If you try to copy the field values to a text field, it's as simple as just using the field code - in your case %{19401}.

What are you trying to implement by using findPatternIgnoreCase?

Do you want to return a list of all available options or only the ones checked?

Best regards,
Thorsten

Marc Jason Mutuc
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.
June 28, 2018

The target field is a Text Field, Single Line.

What I'm getting when I just parse the field is Blue (BL),Red (RD),Magenta (MG),Green (GN) but what I want displayed is BL,RD,MG,GN.

That's why I'm attempting findPatternIgnoreCase but can't really get it to work.

Any other options we can use to get the desired output?

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 28, 2018

Hi @Marc Jason Mutuc,

since you don't want to return the options as is, but are trying to manipulate those values, your expression has to be a litte more elaborate:

toString(textOnStringList(toStringList(%{19401}, ","), substring(^%,length(^%)-3,length(^%)-1)))

In short, the expression iterates over your options, cuts away the first n characters including the bracket as well as the last bracket and then rebuilds a new list with the returned values. If all your options follow the same syntax, this expression should do the trick.

Best,
Thorsten

Marc Jason Mutuc
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.
June 28, 2018

Cool! Can I set a variable for it? or should I just add it in my concatenated text? I would prefer the cleaner one of course! 

Marc Jason Mutuc
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.
June 28, 2018

Dissecting (since I'm not really good at programming :(] )

19401 is a checklist with content checked equals to Blue (BL),Red (RD),Magenta (MG),Green (GN)

%19401 would return Blue (BL),Red (RD),Magenta (MG),Green (GN)
toStringList(%{19401},",") would return ["Blue (BL)","Red (RD)","Magenta (MG)","Green (GN)"]

Setting the above to... say... LST

toString(LST, substring(^%,length(^%)-3,length(^%)-1)) essentially cleans it up.

Uhm... how did ^% get the correct integer? Really sorry. And I would appreciate the walkthrough! I'm sure it would also be helpful to the community.

And the code works perfectly! Just want to understand it more. :)

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 28, 2018

Hi @Marc Jason Mutuc,

^% is a placeholder used by the textOnStringList function. In short, it is used to iterate over each element of the list you created before:

["Blue (BL)","Red (RD)","Magenta (MG)","Green (GN)"]

So with the given list of four elements, the iteration will be done four times and on the first run, ^% will represent "Blue (BL)" and so on.

Since your options all follow the same composition we can then parse those elements by cutting those two characters between the brackets. We're doing so by referencing "get total string length of this option and substract 3" as the start and "get total string length of this option and subtract 1" as the end index.

Obviously, this only works while only having two characters in between the brackets.

Hope this answer helps.

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 28, 2018

Actually, you won't even need the paramters in your toStringList expression.

toString(textOnStringList(toStringList(%{19401}), substring(^%,length(^%)-3,length(^%)-1)))

Should be sufficient as well.

Marc Jason Mutuc
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 23, 2018

Ok. I'm having difficulty coding for three letter codes now. Can you give me a script if the choices are as follows?

Blue (BL)

Red (RD)

Magenta (MAG)

Green (GRN)

I'm thinking of casting but couldn't get it to work. 

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 7, 2018

Hi @Marc Jason Mutuc,

please try the following:

toString(textOnStringList(toStringList(%{11300}),toString(findPattern(^%,"(?<=\\().+?(?=\\))"))))

Using this regular expression should do the trick for any number of characters between brackets.

Marc Jason Mutuc
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.
September 13, 2018

This is awesome! Sorry for just getting back to you now. The old script I was using was 

 

replaceAll(replaceAll(toString(textOnStringList(toStringList(%{19401}), substring(^%,length(^%)-4,length(^%)-1))), "\\s", ""), "\\x28", "")

 

Somehow, it worked. But revisited everything and applied yours. It is much much better! Thank you so much!

Suggest an answer

Log in or Sign up to answer