It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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 Apr 01, 2019

Hi, 

You could use 

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

}

if I got it right.

@Antoine Berry 

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

Hi,

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

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 Apr 04, 2019

Yes exactly !

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 Jul 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

@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 Jul 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 

Hi @Aisha M ,

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

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

Antoine Berry Community Leader Sep 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 !

@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 Sep 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

@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 Oct 07, 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.

@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 

@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"

@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)

Antoine Berry Community Leader Oct 09, 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"

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

@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 Oct 14, 2019

Hi @Aisha M ,

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

@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 Oct 14, 2019

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

@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 Oct 14, 2019

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

@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 Oct 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 ?

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 :(

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

842 views 5 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you