Forums

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

Way to make one field required based on another field selection using scriptrunner behaviors

Joe Harmon
Contributor
April 25, 2023

I have a required field called "Release Type" and when it is set to "Hardware" I want to have the SKU(s) field required.  When it is set to anything else, I want the SKU(s) field optional and read only or if possible hidden.  Here is the script I have so far but it isn't working at all.  I also want the asterisk to show against skus as well if possible.

 

def releaseTypeField = getFieldById(getFieldChanged())

def releaseTypeStatus = releaseTypeField.getValue()

def skusField = getFieldById("SKU(s)")

if (releaseTypeStatus == "Hardware") {
    skusField.setRequired(true) //Sets the SKUs field to required.
    skusField.setHelpText("The SKUs field is required when it is a hardware project")
}
else {
    skusField.setRequired(false) //Sets the SKUs field back to optional
    skusField.setReadOnly(true)
    skusField.setHelpText("")
}

 

2 answers

0 votes
Robb F Watkins
July 20, 2018

I am wanting to use Priority as a required field on the Create Transition as a post function.  But when the field has a value it is not stopped by the post function.  I created a new Priority Scheme and did not select a default and it picked on its own.  

Nic Brough -Adaptavist-
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 Champions.
July 20, 2018

A post function is not a check for data, it is something the system does after the user commits valid data in the transition and says "go".   They don't stop anything (they can, but only by crashing badly, which is a terrible thing to do)

You might want to do this with a validator - these take the entered data and check it, throwing the user back to the screen if the checks fail.

But if all you need to do is make sure a priority is entered on creation, then use the field configuration as intended - make the priority mandatory in that, and your users will have no choice but to pick one when they create an issue.

Robb F Watkins
July 20, 2018

Nic:

Thanks for the response.  Yeah I figured out the validator route after posting my last post.  But the priority requires a default item.  So the field is never blank  / null.  Thus I can not check for an empty field because it is never empty.  I even tried comparing it to a list of regular expressions - allowing the expressions that were in the list. ( Unless I have it written it incorrectly - Option [Blocker,Critical,High,Medium,Low,TBD]  ) But this did not work either. 

I cannot let this go. I have to figure this out.

Nic Brough -Adaptavist-
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 Champions.
July 21, 2018

Ok, but I don't understand the problem now.

You say you want the field to be required, and then that it is never blank/null.  So there is no problem - it's always filled, as required.

I'm sure I am missing something here.

Robb F Watkins
July 23, 2018

Priority Assignment.png

Ok so the ENTER PRIORITY is the default - the product owner wants to force the people entering JIRA tickets to choose one of the other priorities.  So in a validator - I tried allowing regular expressions (except ENTER PRIORITY) but it blocks everything  -  Option [Blocker,Critical,High,Medium,Low,TBD]   I am wondering if the url based Icon is messing that process up?

0 votes
Bastian Stehmann
Community Champion
June 9, 2018

Hi @LusineTerteryan,

 

the priorities can be edited in the priorities section (Cog Menu -> Issues -> Priorities). In one of the latest release, even priority schemes were added, so that you can have different priorities in different projects.

LusineTerteryan
June 9, 2018

Hi Bestian

I want the field to be null and nothing of them set as default.

Bastian Stehmann
Community Champion
June 9, 2018

Hmm, I think you will have to add a priority called "Empty" / "None" / "No Priority" or something like that, because as far as I know, you can not choose to make that field empty.

But maybe somebody else here has a better solution for that.

Robb F Watkins
July 23, 2018

Priority Assignment.png

Ok so the ENTER PRIORITY is the default - the product owner wants to force the people entering JIRA tickets to choose one of the other priorities.  So in a validator - I tried allowing regular expressions (except ENTER PRIORITY) but it blocks everything  -  Option [Blocker,Critical,High,Medium,Low,TBD]   I am wondering if the url based Icon is messing that process up?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events