Forums

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

Elements connect manipulating a variable to use in a query

Deepak Elias November 21, 2022

I would like to do the following. 

1. Extract the issue value which will return a string like "Topic - Title[ID]"

2. Only use the ID from the string above in my query to the data returned by my elements connect JSON using something like. $.data[?(@.attributes.name == "ID")]

I have tried to write the code using split below but it isnt working. 

#set($input = $issue.get("Topic"))
#set($part1 = $input.split("[")[1])

#set($part2 = $part1.split"[")[0]

Part1 is $part1 -> This is always empty.

Is there a way to split a string in the elements connect configuration? Is there a way to use regex?

1 answer

0 votes
Simon Laffont
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.
November 22, 2022

Hello @Deepak Elias

I am part of the Elements support team. 

The toString().replaceAll() function can be used as a regex. Please take a look at the following documentation: Elements Connect - Velocity - String 

screenshot.png

What is the type of the parent field (the one that returns "Topic - Title[ID]"). Is it another Connect field, a basic Text customfield, or something else?

Kind regards,
Simon.

Deepak Elias November 22, 2022

Hi @Simon Laffont thanks for the quick response. The parent field is part of the issue returned by another Connect configuration (so I guess its a Connect field). Still learning JSD. 

To confirm I can do the following. 

#set($regex1 = "/(.+\[)")
Regex1 is $regex1
#set($input = $issue.get("Cloud Application")) --> This will return the "Topic - Title[ID]"
Input is $input
#set($part1 = $input.toString().replaceAll($regex1, ""))
Part1 is $part1
#set($regex2 = "/(\])")
#set($part2 = $part1.replaceAll($regex2, ""))
Part2 is $part2
$.data[?(@.attributes.name == $part2)] --> I just want to the ID part of $input

Simon Laffont
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.
November 22, 2022

@Deepak Elias

Before going any further, we need to know the exact type of the parent field.

If it's a Connect field, you should be able to find it in the Fields tab, via the Elements Connect administration menu:
screenshot2.png

If the parent field is a Connect field, can you please:

  • Tell me if it's a Snapshot or a Live field (please see The different field types)
  • In the case of a Live field, tell me if it's single-value or multi-value

If you wish to continue this conversation in private, feel free to raise a ticket on our support instance, by clicking here.

Kind regards,
Simon.

Deepak Elias November 22, 2022

@Simon Laffont , thanks for the help. 

Happy to keep the conversation going here so others can benefit from anything we find, unless you think otherwise. 

It is a Connect field and its Live. Its a single-value text field. 

Thanks

Simon Laffont
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.
November 23, 2022

Hi @Deepak Elias

Alright.

In the case of a Live field, only the key is stored in Jira and the displayed value remains in the external datasource (the displayed value corresponds to the field template). This means that only the key can be passed from one field to another.

Please see "What is a good key in an Elements Connect field?".

So what you are trying to do (retrieve the displayed value from a Live field) is not possible. When you do that, you get the key. Do you get my point?

Now my question is: what key is currently set in the Parent field? If the ID attribute is the parent field key, then you can get it directly without formatting it.

Kind regards,
Simon.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events