Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,540
Community Members
 
Community Events
176
Community Groups

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

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 Jun 07, 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?

Yes Mahesh, you got my requirement.

Mahesh S Rising Star Jun 07, 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

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.

@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 Jun 08, 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

Great,it works.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events