Hi,
I am writing a script that I need to put in the workflow post function, my need is based on 2 fields values post function will execute it, but I am getting some errors[the variable is undeclared] when i run it on the script console., Please find the below that I'm using it.
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10700")
def cField1 = customFieldManager.getCustomFieldObject("customfield_10728")
def cFieldValue = issue.getCustomFieldValue(cField)
def cFieldValue1 = issue.getCustomFieldValue(cField1)
if(cFieldValue.equals("1") && cFieldValue1.equals("yes")){
return true
}
Thank you.
Your script is using a contextual variable. In a post function for example, a script is running as an issue moves through the workflow. It is running in the context of an issue, and that issue object is therefore available to it.
The console does not have any context. So calls to issue fail because it doesn't know.
Either write your script where it's intended to be run (a test post-function), or you'll need to tell it what issue you want to run it against if you want to run it in the console.
Thanks for your response Nic, so the scripts look good as per my requirement i.e based 2 fields values post-function should execute, can you confirm me? and when i kept this script on post function but nothing is happening.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will need to read the logs to see if it is crashing.
As given in the question, I wouldn't expect it to do anything at all - it either does "return true" or ends with no further action - those won't do anything in the UI
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.