Greetings :
I am currently looking to achieve a situation where workflow auto transition would be done based on triggers based on custom field value. I am using Script Runner add-on which has in-built feature to do so.
I have chosen Generic Event to fire the trigger and condition as cfValues['customfield_12345'] == 'xyz'
provided target field is a free text field. However i am not able to make it working, any idea what am i missing?
To be more precise, can you please explain with a complete example?
My understanding is, you need a script to push an Issue from one state to another state when the value of 'customfield_12345' is set to 'xyz'. Am I right?
Yes Mahesh, you got my requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Basically, you need to fire a trigger. But, since it happens from a simple field value edit, you cannot go via a workflow post function. Please question me if this is not clear.
It can be solved using a Scripted field.
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField samp = customFieldManager.getCustomFieldObjectByName("customfield_12345_Name")
String sampVal = (String) issue.getCustomFieldValue(samp)
if(sampVal.equals("xyz")
{
issue.setResolutionId("7")
log.debug ("issue.statusObject.name: " + issue.statusObject.name)
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setUsername(currentUser);
workflowTransitionUtil.setAction(161)
CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
String comment = "Moving to B state since Sample value is xyz";
commentManager.create(issue, currentUser, comment, true);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
Kindly let me know the results. The above code could be used as a reference. Apologies, I couldn't test and provide the exact code since I'm not in my work station.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
Thanks for your reply, unfortunately we cannot create any new custom fields since this project is already live and we could not make any such changes.
However i found one solution to do this is with Script Runner plugin's listener (Fast-track transition an issue). As of now its not working for me but i am trying it sort it out. Thanks for your help so far.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin (Adaptavist)
Hello Jamie,
Can you please help in sorting the issue with Script Runner plugin's listener (Fast-track transition an issue).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the 'Fast-Transition an Issue', we can provide the condition and a transition Id, which moves when it is true. Please provide the below script in the condition.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.IssueImpl import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.project.ProjectManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue boolean status = false IssueManager issueManager = ComponentAccessor.getIssueManager() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() CustomField myCustomField = customFieldManager.getCustomFieldObjectByName("custom_field_Name") String myCustomFieldVal = (String) issue.getCustomFieldValue(myCustomField) if(myCustomFieldVal.equals("xyz"){ status = true } return status
And then, provide your transition Id in the Action dropdown.
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.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.