The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

CONDITIONS FOR WORKFLOW STEPS USING GROOVY SCRIPT

Camelia
September 18, 2017

import com.atlassian.jira.component.ComponentAccessor

import java.sql.Timestamp

if (issue.getIssueType().getId() == "193") {
   if (issue.getWorkflowId == "<to check the workflow step id... what to insert here? and where to get it?>") {
      issue.setDueDate(new Timestamp((issue.dueDate + 3).time)) // set due date
   }

  if (issue.getWorkflowId == "<to check the workflow step id... what to insert here? and where to get it?>") {
      issue.setDueDate(new Timestamp((issue.dueDate + 7).time)) // set due date
   }
}

 

This groovy script will check for conditions by the workflow step id. How can I do so? Can anyone show me the code? Urgent. Need help ASAP. Thanks in advance.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Nic Brough -Adaptavist-
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 Champions.
September 19, 2017

That's going to be hard work if I remember the API correctly.

Why don't you just use two scripts, one on each post-function?

Camelia
September 19, 2017

I thought of making it all in one script because I might need to add more codes for different days for each workflow steps.

If there's like 10 set of different days, that would be 10 scripts.

Which one is the best solution for this matter? If the one with conditions is the best, if you don't mind show me a sample of the code.

What would you suggest, Sir?

Thank you.

Cam.

Nic Brough -Adaptavist-
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 Champions.
September 20, 2017

Ok, if you use the id's, you'll need some (potentially unpleasant) code to find them.

I'd take a different route.  If you wrote 10 scripts and saved them as files in the scripts directory, you could use them repeatedly without thinking about transtion ids.  You'd say "use script add-4-days for this transition" and for the next one "use script add-6-days", and for a third, reuse add-4-days.  It'll keep your scripts very short and simple.

Another option is a bit longer - you could use a single script that reads a transition property that you add to transitions, which is a lot easier to get to in a post-function than the id.  Also means one script keeps it really simple!

Camelia
September 20, 2017

Hi Sir,

Oh, I see. And if I may ask, could you provide and show me the code for it?

As I'm not really familiar with it.

I appreciate if you could lend me a hand.

Thank you.

Cam.