Forums

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

Need help on a scripted validator

Rachid El Mansouri January 12, 2023
Hi experts, 
I have a problem on my following scripted validator. 
I want to prevent transition if value of custom field "Origin" is different to "IVV".
The script always return false even if value of my single select is equals to "IVV"
Thank you for your help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

 

def issueManager = ComponentAccessor.getIssueManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def OriginCf = cfManager.getCustomFieldObject("customfield_10404")
def OriginValue = issue.getCustomFieldValue(OriginCf)


log.warn("OriginValue =  "+ OriginValue)

// this return IVV
if (OriginValue.equals("IVV"))
{  
    return true
}
else
{
    return false
}

1 answer

1 accepted

0 votes
Answer accepted
Fabio Racobaldo _Catworkx_
Community Champion
January 12, 2023

Hi @Rash ,

is Origin field on the transition screen ? Moreover could you indicate custom field type?

Fabio

Rachid El Mansouri January 12, 2023

Hi  @Fabio Racobaldo _Catworkx_ ,

Thanks for your quick reply.

The Origin field is "Select List (single choice)" and is on the screen otherwise it will not get its value.

Fabio Racobaldo _Catworkx_
Community Champion
January 12, 2023

Hey @Rash ,

try this code :

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.fields.CustomField;

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager();
CustomField OriginCf = cfManager.getCustomFieldObject("customfield_10404");
Option originValue = issue.getCustomFieldValue(OriginCf)!=null?(Option)issue.getCustomFieldValue(OriginCf):null;

log.warn("OriginValue = "+ OriginValue)

// this return IVV
if (originValue!=null && originValue.getValue().equals("IVV"))
{
return true
}
else
{
return false
}

Hope this helps,

Fabio

Rachid El Mansouri January 12, 2023

This works.

Thanks for your help @Fabio Racobaldo _Catworkx_ 

 

Have a nice day.

Fabio Racobaldo _Catworkx_
Community Champion
January 12, 2023

I'm happy for that. Have a nice day @Rash 

Suggest an answer

Log in or Sign up to answer
TAGS
Atlassian, Team '25 Europe, Atlassian conference, AI-powered teamwork, Atlassian events, keynote speakers, Barcelona tech conference, Atlassian Williams Racing, Carlos Sainz, Jenson Button, Mike Cannon-Brookes, Anu Bharadwaj, Atlassian Rovo

Atlassian Williams Racing is coming to Team '25 Europe 🏎️

Discover the teamwork and precision behind success on and off the track. See how this high-performing team makes the impossible possible. Be one of the first 100 customers to register for a chance to win 2 tickets to an Atlassian Williams 2026 race.

Register now
AUG Leaders

Atlassian Community Events