Script runner - Fast-track transition based on custom field value

Deleted user June 7, 2016

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?

 

 

1 answer

1 accepted

1 vote
Answer accepted
Mahesh S
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.
June 7, 2016

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?

Deleted user June 7, 2016

Yes Mahesh, you got my requirement.

Mahesh S
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.
June 7, 2016

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. smile

It can be solved using a Scripted field.

  • Create a scripted field 'xyz'. Add to field configuration & hide it from the screens.
  • This scripted field should take the 'customfield_12345' value and check whether it is 'xyz' or not.

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();
}

  • Specify the ResolutionId and JIRA status Id in setResolutionId and setAction respectively.

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. smile

Deleted user June 8, 2016

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.

Deleted user June 8, 2016

@Jamie Echlin (Adaptavist)

Hello Jamie,

Can you please help in sorting the issue with Script Runner plugin's listener (Fast-track transition an issue).

 

Mahesh S
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.
June 8, 2016

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.

 

Like Chhaya Gadade likes this
Chhaya Gadade August 20, 2019

Great,it works.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events