Forums

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

Scriptrunner - Update a script variable through code

Philippe LECOMTE July 31, 2018

hi,

I'd like to update via a script a "Scriptrunner script variable".

For my example, each of my new ticket must get a new specific delivery date based on the last delivery date assigned + 3 days.

I'm using the script variable NEXT_DUE_DATE to do that :

logger.info("My script variable current value : " + NEXT_DUE_DATE)

// Date.parse() to convert String to Date.
Date date = new Date()
date = date.parse('dd/MMM/yy', NEXT_DUE_DATE)

date=date+3

NEXT_DUE_DATE = date.format("dd/MMM/yy")

logger.info("My script variable new value : " + NEXT_DUE_DATE)

My code doesn't display errors but the script variable value doesn't change.

Any idea ?

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
August 1, 2018

Hi Phillipe,

Thank you for your question.

I can confirm that script variables are designed to store values which can be injected to scripts and used in scripts as described here but that you cannot change the value of a script value from a script due to the security restrictions which Atlassian place on Jira Cloud. 

This means that for your script that you will be able to update the data value inside the script and can store it inside a local variable for when that script is run but that you cannot persit the value back to the Script Value field. 

If this response has answered your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,
Kristian

Philippe LECOMTE August 1, 2018

Hi Kristian,

Thanks for your answer...

Any lead i could use to manage a "global variable" useable through scriptrunner ?

Regards,

Philippe

Kristian Walker _Adaptavist_
Community Champion
August 1, 2018

Hi Philippe,

Unfortunately it is not currently possible to have a global variable which can be wrote to and shared between scripts.

One way you work around this is to have an specific issue which has a field on it to store the value for the variable and then to read  the value from and write the value to that issue each time you need to.

I understand that this is not ideal but currently it would be the only way to achieve this requirement. 

Thanks

Kristian

Philippe LECOMTE August 1, 2018

Thanks Kristian,

I just wanted to make sure i had no other simple choice.

Regards,

Philippe 

Suggest an answer

Log in or Sign up to answer