JIRA - ScriptRunner Simple Scripted Validator: Custom Field Not Equal to Default Value

Stephen Williams August 11, 2017

Hi All,

My use case requirement is that only issues of the Story type must have non-default values for 2 specific custom fields before it can be moved in the workflow. The default value for each is set to None.

Requires UI Scrub: None/Yes/No

Docs Impact: None/Yes/No

I'm trying to use the ScriptRunner Simple Scripted Validator to do this, but the script seems to always return false, even if Yes/No is selected.

Here is the script, any ideas? I'm simply using one script for each and just changing the name.

Pardon my syntax, feel free to correct as I'm not too familiar with Java.

if (issue.issueType.name == 'Story')
{
if (cfValues['Requires UI Scrub']?.value != 'None')
{
return false
}
else return true
}
else return true

 

Here is the payload from the ScriptRunner logs:

{
    "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.validators.SimpleScriptedValidator (java.lang.String)",
    "class.name": "com.onresolve.jira.groovy.GroovyValidator (java.lang.String)",
    "issue": "SWTP-13 (com.atlassian.jira.issue.IssueImpl)",
    "passesCondition": "true (java.lang.Boolean)",
    "transientVars": {
        "issue": "SWTP-13 (com.atlassian.jira.issue.IssueImpl)",
        "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@627a65ad",
        "proj": "Project: SWTP (com.atlassian.jira.project.ProjectImpl)",
        "project": "[GenericEntity:Project][name,Stephen Williams Test Project][assigneetype,3][description,][projecttype,software][id,15606][counter,5][avatar,11303][originalkey,SWTP2][url,][lead,stephen.williams][key,SWTP] (org.ofbiz.core.entity.GenericValue)",
        "currentSteps": "[SimpleStep@1[owner=, actionId=0, status=open]] (java.util.ArrayList)",
        "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@7c32f7bf",
        "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@28c7d081",
        "userKey": "stephen.williams (java.lang.String)",
        "originalAssigneeId": "null (org.codehaus.groovy.runtime.NullObject)",
        "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@4c34ba63",
        "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@546d7c7a",
        "originalissueobject": "SWTP-13 (com.atlassian.jira.issue.IssueImpl)",
        "actionId": "11 (java.lang.Integer)",
        "pkey": "SWTP (java.lang.String)",
        "transaction": "com.atlassian.jira.transaction.TransactionSupportImpl$TransactionImpl@584e9cbd"
    },
    "log": "org.apache.log4j.Logger@59e178c9",
    "invalidInputException": "[InvalidInputException: [Error map: [{}]] [Error list: [[You cannot move to Assigned until you select 'Yes' or 'No' for Requires UI Scrub in the Edit screen.]]] (com.opensymphony.workflow.InvalidInputException)"
}

 

We are using JIRA Server. Thanks!

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.
August 13, 2017

Hi Stephen,

So what is happening is that the None value is actually the no value or null value. Therefore your validator and supposing that the fields you want to check is a radio button or a select list, should be something like 

if (issue.issueType.name == "Story") { 
return cfValues['RadioButtons']?.value && cfValues['SelectListA']?.value
}

true

The best thing to try in order to troubleshoot cases like that, is to add some debug messages in order to see what value the field has during the transition. Something like 

def radioButtonValue = cfValues['RadioButtons']?.value
log.warn "Radio button value is $radioButtonValue
"

and check your logs to ee the value and then eidt your validator...

Hope that helps.

regards,

Thanos

Suggest an answer

Log in or Sign up to answer