Forums

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

Prevent workflow transition with groovy script condition

Laurel Moczydlowski May 8, 2018

I'm trying to prevent a transition if a custom date field "Date for Removal" is not in the future. However everytime I do I get an error that says it can't find the custom field. I'm relatively new to Groovy so this is what I have thus far, any idea what I'm missing?

 

issue.getDateforRemoval < getDate()

2 answers

1 accepted

0 votes
Answer accepted
Tarun Sapra
Community Champion
May 8, 2018 edited

You have to use the correct APIs, try this

import com.atlassian.jira.component.ComponentAccessor;
import java.util.Date;

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateForRemoval= customFieldManager.getCustomFieldObjectByName('Date for Removal'); 
def removalDateValue = issue.getCustomFieldValue(dateForRemoval) as Date
Laurel Moczydlowski May 8, 2018 edited

Thanks!  @Tarun Sapra

 

So to allow the transition if the date value is not the future it would be

 

Date <= getDate()

 

Or am I completely botching that?

Tarun Sapra
Community Champion
May 9, 2018

No it would be 

Date now = new Date()

and then

removalDateValue > now

If removalDateValue is in future.

0 votes
Adrián Plaza [DEISER]
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.
May 8, 2018

Hi @Laurel Moczydlowski,


Can you share the complete script that is you using?

 

Cheers,
Adrián.

Suggest an answer

Log in or Sign up to answer