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 _Herzum_
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 _Herzum_ ,

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

 

Have a nice day.

Fabio Racobaldo _Herzum_
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