Can I use a IF condition in the Simple Scripted Validator?

Is it possible to use a IF condition in a Simple Scripted Validator? I am trying to build a validator for the below objective, can some one help?

If (Condition1 = true)

set custom field values = "A"

else if (Condition2 = true)

set custome field value = "B"

else

set custom field values = "C"

3 answers

1 accepted

Sorry, my example is misleading, actually it is supposed to like this:

If (Condition1 = true)

set field "A" mandatory

else if (Condition2 = true)

set field "B" mandatory

else

set field "C" mandatory

 

Certain fields should become mandatory based on certain conditions. e.g. if a check box is checked, one of the text field is mandatory.

You can try creating your own script and it in the "Script Validator"

Can you please provide me a sample script, I can develop mine based on that.

If I understand it correctly, the Scripted Validator is to validate something first and  restrict the transition if it fails. It doen't update anything. I think what you are looking for is a Post-Function "Update Issue Field" using JIRA Suite Utilities.

Reference: https://confluence.atlassian.com/jira/how-to-update-custom-field-values-during-workflow-transition-310378700.html

Hi Gabrielle

Developed the below code, any idea whats wrong with the IF loop? My code inside the IF condition is not executed at all even though the condition is true. cfenvironmentvalue is the value from a Drop Down field.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.resolution.Resolution
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
 
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cfjiraorjama = customFieldManager.getCustomFieldObjectByName("Item(s) are Managed in JIRA or CATS?")
CustomField cfenvironment = customFieldManager.getCustomFieldObjectByName("Build Environment (Subversion)")
CustomField cfPcrBundDelNum = customFieldManager.getCustomFieldObjectByName("PCR/Bundle/Deliverable Numbers")
CustomField cfUatCatsConf = customFieldManager.getCustomFieldObjectByName("UAT: CATS Confirmation")
CustomField cfUatJiraConf = customFieldManager.getCustomFieldObjectByName("UAT: JIRA Confirmation")
CustomField cfTrnPrdCatsConf = customFieldManager.getCustomFieldObjectByName("TRN/PRD: CATS Confirmation")
CustomField cfTrnPrdJiraConf = customFieldManager.getCustomFieldObjectByName("TRN/PRD: JIRA Confirmation")


IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
MutableIssue myIssue = issueManager.getIssueObject("CAR-1928")
 
def cfjiraorjamavalue = myIssue.getCustomFieldValue(cfjiraorjama)
def cfenvironmentvalue = myIssue.getCustomFieldValue(cfenvironment)
def cfPcrBundDelNumvalue = myIssue.getCustomFieldValue(cfPcrBundDelNum)
def cfUatCatsConfvalue = myIssue.getCustomFieldValue(cfUatCatsConf)
def cfUatJiraConfvalue = myIssue.getCustomFieldValue(cfUatJiraConf)
def cfTrnPrdCatsConfvalue = myIssue.getCustomFieldValue(cfTrnPrdCatsConf)
def cfTrnPrdJiraConfvalue = myIssue.getCustomFieldValue(cfTrnPrdJiraConf)
def result
 
if (cfenvironmentvalue=="PRD"){
result = cfjiraorjamavalue
} else {
result = cfenvironmentvalue
}
return result

 

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

181 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you