Need help on executing script using adaptavist scriptrunner

Hello December 27, 2017

Need help on running scriptrunner tasks.


Hi All,

I am having few customizations to be made, I have been asked to use scriptrunner to write the scripts. Can anyone please help me with any complete cycle of script.?
I am having backgruond in Java, so groovy (scripting language of the tool) shouldn't be an issue, but I don't know from where and how to run the scripts.
The problem statement is, I am having 1 custom field, and I need to mark it compulsory for specific status and I also want to make it display  on the specific condition.(For instance the custom field should be only displayed when issue status is in "In progress" or "completed" state)

Any suggestions are welcomed.Moreover any document/article/video as well should be fine if it depicts a complete cycle of scriptrunner flow.

 

Thanks

2 answers

0 votes
Hello January 1, 2018

We have 2 custom fields and we want to change the value of field 1 dynamically based on the value of field 2(For instance, when field 2 will have some value then field1 should be mandatory and if field 2 has no value then field 1 should be non mandatory).We need some kind of function in scriptrunner which is similar to  jQuery onChange() .Please let me know how this could be achieved ?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 1, 2018

Ok, that is the sort of thing Behaviours are for.

It seems you have not yet looked at creating a Behaviour, otherwise you would have seen that it asks you for information that can guide you through this reasonably easily.

Select a field to run the behaviour on, (Probably field 1 in your case), and then add the code for your logic.  When you go into the editor for the code, look beneath it, as it has a quick reference guide for things like "get current field data", "set field data on-screen", "show/hide field" and "set field optional/required".

Hello January 1, 2018

JIRA_Reference.PNGHere in above image can you please tell that which method will be helpfull for below task :

"We have 2 custom fields and we want to change the value of field 1 dynamically based on the value of field 2(For instance, when field 2 will have some value then field1 should be mandatory and if field 2 has no value then field 1 should be non mandatory).We need some kind of function in scriptrunner which is similar to  jQuery onChange() .Please let me know how this could be achieved ?"

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 2, 2018

I'd use the getFieldByName and setRequired you found in the table of help.  It's good to read and learn new stuff.

Hello January 2, 2018

yes...Can you  please help to suggest to solve below problem 

"I have  2 custom field (for DATE) , If I select any date from 1 field than in another filed DATE PICKER should show equal or greater date of SELECTED date of 1st field. I can say in 2nd date field DATE PICKER should DISABLE the EARLIER DATE  from selected 1st Field date. And the 2nd field should not accept earlier date than selected date of 1st field [if user change manually after selecting 1st date]

So can you suggest how can I achieve ??   "

0 votes
Alexey Matveev
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.
December 27, 2017

If you are on Jira Server/Data Center then you could use behaviours

https://scriptrunner.adaptavist.com/4.3.1/jira/behaviours-overview.html#_description

Hello December 27, 2017

Thanks for update.  

I have written Script to connect database having table containing 

data. Still it is retrieving null in output.

Please suggest me if any step left ??

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 28, 2017

That is not the right approach to writing the Behaviours and validators to solve your problems.

Could you explain where you're actually stuck

Alexey Matveev
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.
January 2, 2018

You should use

getFieldByName to get your custom fields

def cs1 = getFieldByName("customField1Name")

def cs2 = getFieldByName("customField2Name")

then you should check the value and set the other field to required

if (cs1.getValue().equals("value")) {

cs2.setRequired(true);

} else {

cs2.setRequired(false);

}

Hello January 2, 2018

ok. Thank you so much Alexey.

Suggest an answer

Log in or Sign up to answer