Need help with Scriptrunner ? Hw to limit one issue type from going through a check ?

Aisha M March 31, 2019

Hi,

 

I have the below snippet of code to ensure "Work Type" field is filled in order for the issue to move to DONE.

def workType = GetWorkType(issue);
if(workType == null || workType.isEmpty())
{
errors.add("Work Type is required to accept this ${issueType}");
}

How do I limit this code to not include RISK issue type alone?

 

Thank you 

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 1, 2019

Hi, 

You could use 

if (issue.getIssueType().getName() != "Risk"){

}

if I got it right.

Aisha M April 4, 2019

@Antoine Berry 

Thank you for the comment. Where must I add the above line , with respect to the scriptI have shared. 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2019

Hi,

That would be the first line of the script I guess. Place your script inside this condition.

Aisha M April 4, 2019

Hi,

Something like this, ?

if (issue.getIssueType().getName() != "Risk"){
def workType = GetWorkType(issue);
if(workType == null || workType.isEmpty())
{
errors.add("Work Type is required to accept this ${issueType}");
}
}

Thanks

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2019

Yes exactly !

Saravanan Ravikumar July 24, 2019

Need to restrict the Issuetype (bug) movement to only particular issue types (story or task) , User (role wise) should able to move only to particular issue type mentioned not all the available issue types.

Is that possible ?

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 24, 2019

Afaik it is possible with the clone plus plugin (which I am using). If you need more assistance I would advise to raise a new question.

Antoine

Saravanan Ravikumar July 24, 2019

@Antoine Berry Is that possible using scriptrunner or any other plugin. Because we don't use the Clone plus plugin.

 

Regads

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 24, 2019

Maybe you could create a custom web section, but I do not know if it can fullfill all your requirements...

I have not done it so if you face any difficulty you should raise a new question so the community can help you.

Good luck !

Antoine 

Aisha M August 7, 2019
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 26, 2019

Hi @Aisha M ,

Sorry I was out of office for vacations. Do you still have the issue ? The answer on this topic seems correct.

Aisha M September 4, 2019

@Antoine Berry Please don't be sorry :) You are already doing such an amazing help :) And yes, the issue has been fixed :) Thank you !

Aisha M September 18, 2019
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 24, 2019

Hi @Aisha M ,

It looks like you got plenty of help from experts, I agree with what they said, you should probably set the date value in the create post-function !

Aisha M September 25, 2019

@Antoine Berry  Thank you so much for looking into it :):) Until I get the go from you, I just couldn't finalize on anybody s answer. . :D You always give the best possible solution !

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 25, 2019

Ahah, I do my best, but these guys are probably better :) Let me know if you need further help.

Like Aisha M likes this
Aisha M October 4, 2019

@Antoine Berry  Well regrading that workflow post function question. My team doesn't want to add the post function to every workflow. They are suggesting something like, a script runner script that checks the value every (whatever frequency we determine), and fills it in?  You think that is possible 

Thank you 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 7, 2019

Hi @Aisha M , you could probably use services, but I would strongly suggest to use post-functions even if you have to add it to multiple workflows. It is fast to set-up and you are sure your script will only run when needed.

Aisha M October 9, 2019

@Antoine Berry I was told to look if script listeners could be used :( My team does NOT want to use post functions for some reason :D

And just a quick question, while writing scripts, how should we include multiple types,

For example, If i want to include RISK & TEST in below code,

if (issueType != "Risk")

Should it be, 

if (issueType != "Risk","Test")   (OR) if (issueType != "Risk""Test")

Thank you 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 9, 2019

@Aisha M you could absolutely create a script listener on the Create Issue event. Make sure you are triggering this event in the workflow. If you need actual help you can open a new thread.

As for the script you could use

issueType in ["Risk", "Test"]

 or

issuetype == "Risk" or issueType == "Test"
Aisha M October 9, 2019

@Antoine Berry  I will open a thread for it then :) Thank you . . 

Well, I tried as below, 

if (issueType != "Risk") && (issueType != "Test"
 (issueType != "Risk") || (issueType != "Test"

 Actually, this works fine for Risk, but doesn't work for Test (actually its for the same question as this original thread, but we are extending it to TEST issue type as well)

Aisha M October 9, 2019
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 9, 2019

@Aisha M , If you want your script to not execute when issue type is Risk or Test, you should use : 

if (issueType != "Risk" && issueType != "Test"){...

 If this does not work for Test, this means there is a type. Add 

log.error("issuetype:  " + issueType)

and make sure it is exactly "Test"

Aisha M October 9, 2019

@Antoine Berry  Yeah, it didn't work either. Don't know why. Okay, I ll log and check

Aisha M October 10, 2019

@Antoine Berry  Hi Antoine. Can you please help me with Listeners in the below thread please,

https://community.atlassian.com/t5/Jira-questions/Need-help-with-Script-Listeners-to-copy-and-lock-a-field-value/qaq-p/1198878#M382444 

Would really appreciate your help :) Thank you ! 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2019

Hi @Aisha M ,

Did you try the solution he suggested ? Are both the date fields custom fields ? Date pickers ?

Aisha M October 14, 2019

@Antoine Berry  Yay yer back ! :)

You mean with he post functions ? Well, that didn't work, but I was being sternly told not to use Post functions, and stick to script listeners or scriptrunner 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2019

The code in post functions and script listeners would be the same :)

Aisha M October 14, 2019

@Antoine Berry  Oh, is it ? I have never used listeners. Can you please help me on how to use listeners for this ? :)

Also, can you please reply in the above thread, so that I can mark your answer :) Should be helpful if anyone wants to try a similar thing :)

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2019

Yes I will take a look at it. Please tell me the configuration of the two fields, are they both date pickers ?

Aisha M October 14, 2019

@Antoine BerryThank you !  Below are the details

Field 1) Epic Due Date

Field 2) Baseline Due Date (Date picker)

I want to make sure that Field 1 copies the value of Field 2 the FIRST time its filled while the issue is created. Later , even thought the Field 2 value might be changed, the field 1 must not change its value and must be non editable (only viewable).

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2019

I am not sure to understand. Are they both custom fields ? So "Epic" due date has nothing to do with an Epic ? Is one of them the Due Date system field from jira ?

Aisha M October 14, 2019

Actually both are custom fields. Not the inbuilt one from JIRA

Basically both of these fields will be available at Epic issue type

And Field 1 should not be editable (only be viewable) on the issue card.

So, this field 1 must pick the first value entered for field 2. 

Field 2 is editable and can be changed multiple times.

 

I hope I was able to explain :(

Aisha M December 4, 2019

Hi @Antoine Berry  Hope you are doing good. :)

If possible, can you please help me with your thoughts on the below question,

https://community.atlassian.com/t5/Jira-questions/Need-help-with-copying-a-date-value-from-one-field-to-another/qaq-p/1242861#M394718

Would really appreciate your help. Thank you 

Suggest an answer

Log in or Sign up to answer