Forums

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

Indexing variables within variables when there's a space in the name?

Brandon Lawler
Contributor
March 7, 2019

Hi all,

I've encountered a problem that I can work around but it's a pretty ugly hack, I'm wondering if there's a better way to do this. I need to use string.replace() to, within a long block of text, swap all occurrences of the value of one field to the value of another field. (I do this dynamically instead of flat substitution because it's a generalized rule that will fire for multiple use cases.) For example, start with :

  • issue.description = "Fruit Summary:<br>FRUIT_1<br>FRUIT_2<br>FRUIT_3"
  • issue.fruit placeholder = "FRUIT_2"
  • issue.fruit type = "Banana"

The rule:

  • RULE1: issue.description = "{{issue.description.replace(issue.fruit placeholder,issue.fruit type)}}"
  • Expected description: "Fruit Summary:<br>FRUIT_1<br>Banana<br>FRUIT_3"
  • Actual description: "Fruit Summary:<br>FRUIT_1<br><br>FRUIT_3"

I don't actually get any errors, it says it ran successfully, but trying to index "issue.fruit placeholder" from WITHIN a smart variable's function does not work the way it does if I just index {{issue.fruit placeholder}} directly. The weird part is that it seems to be because the name of the variable has a space in it. If instead, I make a fields called "cache1" and "cache2" and do this, it works:

  • RULE1: issue.cache1 = "{{issue.fruit placeholder}}"
  • RULE2: issue.cache2 = "{{issue.fruit type}}"
  • RULE3: issue.description = "{{issue.description.replace(issue.cache1,issue.cache2)}}"
  • Actual description: "Fruit Summary:<br>FRUIT_1<br>Banana<br>FRUIT_3"

That works fine. So, it definitely seems to be the spaces. Is there any way to index variables with spaces in the names other than writing out the spaces, so that they are able to be indexed from within functions? Or am I missing some weird detail here?

1 answer

0 votes
Scott Harwood
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.
March 14, 2019

Hi Brandon, 

Instead of using the field name, can you please try use the custom field id instead. E.g {{issue.customfield_1234}}

Let me know if that works for you.

Cheers,

Scott.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events