Forums

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

ScriptRunner: How can I change an issue field by the concatenated values from other issue fields?

dD
Contributor
September 23, 2021

Hello Community,

in Jira Automation I changed the Summary by concatenating two other issue field values as you see in the following figure.

figure 1.GIF

Now I want to achieve the same result using Script Runner. Therefore I am trying to set an Behaviour, which fail. In the following figure I show you my script. Maybe I also have to use a listener instead but first of all I want to understand the basic script structure :)

figure 2.GIF

2 answers

1 accepted

3 votes
Answer accepted
Will C
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 23, 2021

Hi there, your script looks like it should work but can I just check what the 2 fields are? I'm presuming these are custom fields, so you might need to use this instead - 

def maxToleranceDateCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Max Tolerance Date")
def maxTolerancedatestartingvalue = underlyingIssue?.getCustomFieldValue(maxToleranceDateCustomField)

 

something along those lines, obviously change my field name for your field names.

Also if the fields are on the form you can use 

def CFFieldVal = getFieldByName("Insert Custom Field Name").getFormValue()
dD
Contributor
September 23, 2021

Thank you Will C for your support! I really appreciate that!!!

 

I changed my script using yours and I think we are way closer to the target. but some errors still remain. 

figure 3.GIF

as you see I did some imports, because I thought these would solve the problem. BTW do I have to always do some imports when I am using functions like this?

Then I believe the "-" character causes the last problem. In my automation rule from above I also used this as a seperator. The aim is to create summarys like "KDT-002". I dont want to subtract one from another. How am I supposed to code that? (BTW how would I do this if I literally would want to subtract, add or multiply fields with another?)

And lastly, could you please explain what you mean with "Also if the fields are on the form you can use". So what form do you mean? 

Already best thanks to you

Will C
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 23, 2021

There are multiple ways to achieve the string you want :

(Customfield1 + "-" + customfield2)

("${customfield1}-${customfield2}")

 if you wanted to subtract one from another I'm guessing they are both integers you can do just customfield1 - customfield2.

so using getFormValue() gets the value of that field on the form at that time, whereas underlying issue will get the value that is already saved to the issue.

I hope that all helps?

Like dD likes this
dD
Contributor
September 23, 2021

Best thanks to you, I have finally no errors in this script :)

To achieve the string I tried both variants - but only the second one did work. In the figure below you see the error message I get using the first way.figure 4.GIF

Also I needed to change the "ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(xxx)"-method in "ComponentAccessor.getCustomFieldManager().getCustomFieldObject(xxx)", to made this work.

Like Will C likes this
Will C
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 23, 2021

That error is just static type checking and can be ignored in scriptrunner

Like dD likes this
dD
Contributor
September 23, 2021

Alright :)

Do you know whether I am correct with using a Behaviour? Or do I have to use a Listener or whatsoever? Because I dont know how I can adjust, that this behaviour will be executed every time an issue of an specific issuetype is created or updated

0 votes
dD
Contributor
September 23, 2021

In my Jira Automation Rule I defined that the Rule is triggered when an Issue (specific issuetype) is created or updated. I also want this in my ScriptRunner Behaviour. I guess I have to write it in the initialiser section. But I dont know what. Could you help me out?

Suggest an answer

Log in or Sign up to answer