Hi David,
Based on the only requirement below of "Set Issue Label using last Status Name", i have enclosed a
simple script below which will get the previous status the issue was in and set it as a label on the issue.
Please note that the code must be placed as the first function in the list of post functions in order to get the previous
status and if it is placed after the Get current Destination Step post function then it will return the current status.
/* * @Setup Notes: This piece of code should be configured as a * script function and placed first in the list to get the previous status. * @Setup Notes: If this code is placed after the Get current Destination * Step post function then it will return the current status. */ // Required Imports import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.issue.MutableIssue // Get the current logged in user def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()//Get a to // Get a pointer the current Issue MutableIssue myIssue = issue // Get access to the Label Manager LabelManager labelManager = ComponentAccessor.getComponent(LabelManager) // Get the last status and replace any spaces with a - character as labels must be a single word def previousStatus = issue.statusObject.name.replaceAll("\\s","-").toString() // Check if the Issue has just been created and add a label only if the issue was not previously in the Create status. if (previousStatus != "Create") { // Set a Label with the previous Status Name on the issue labelManager.addLabel(user, issue.id, previousStatus, true) } // Save the issue issue.store()
I hope this helps.
Thanks
Kristian
Hi, I'd be interested in that topic too. Could you please precise which kind of post-function we must use? Am i correct by understanding that we copy/paste the script above in the description box of the post-function selected? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This should be placed as a custom script post function on the transition of the workflow that you want it to execute for. For example if you have a transition going fro To Do -> In Progress then placing it on the transition in between those statuses then it will get the previous transition of To Do and set it to the label. It must be placed as the first post function in the list to get the previous status. Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thanks for your prompt answer.
could you just precise where I can write the custom script? which post function, among the ones in the attached screen shot, do I have to select to feed it with the custom script.
I get it that I have to select the transition between 2 status, then the post function: but there several post-function types :
Many thanks
Melissa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mel, It looks as if you do not have the Script Runner add on installed. When you install Script Runner you will see a Script Post Function option and a Custom Script Post function below that. Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Script Runner documentation here shows how to get the previous workflow status and this code sample could be extended so you set the returned value as a label on the issue.
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's only half a question here...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.