Wanted to block a transition based on custom field value.

Raj Kumar July 18, 2019

Hi Stephen,

I want to block transition when my custom field( Radio Button id is 14403) value is "No" I want a transition to happen only when a custom field value is "Yes".

Can you please help me where I am going wrong with my script? Many thanks

Here is the script I am using.

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObject("customfield_14403")

if (issue.getCustomFieldValue(customfield) == 'Yes') {
return false
} else {
return true
}

 

Thanks,

Raj

1 answer

0 votes
Thanos Batagiannis _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 Leaders.
July 19, 2019

Hi Raj,

You will need a Simple scripted validator and your script should look something like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObjects(issue).findByName("RadioButtons")

def selectedValue = issue.getCustomFieldValue(customfield) as LazyLoadedOption
selectedValue.value == "Yes"
Raj Kumar July 19, 2019

Hi @Thanos Batagiannis _Adaptavist_ ,

I am Getting below mentioned error on the transition before the required transition where exactly validator is placed.

I am also attaching the workflow for your reference.

In the workflow the validation should happen on "Completed" at status Pending Application Access" But it throws the below given workflow error when I click on "Approve" Transition. Can you please help fix this problem.WF.png  

Error Message.png

Thanos Batagiannis _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 Leaders.
July 19, 2019

Not sure where you placed the validator 

Raj Kumar July 19, 2019

Hi @Thanos Batagiannis _Adaptavist_ ,

I have placed it on completed transition between Pending Application Access and Pending Task Completion status.

As I wanted validation to happen when I click on completed transition and block the transition if the custom field value is "NO"Validator.png

Thanks,

Raj

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events