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,364,036
Community Members
 
Community Events
168
Community Groups

postfunction problem with conditional with JMWE

Edited

Copy Value From Field to Field post function

I was trying to make a postfunction that copies the due date to the end date

but only when the end date field is empty

because they may be different, when they are different they should not copy.

 

all of these are custom fields

 

help!!

 

PF.PNG

4 answers

1 accepted

3 votes
Answer accepted

You seem to be using a very old version of JMWE. In more recent versions, you would have a simple checkbox to check: "Copy only if not set"

If you don't want to update JMWE, you can use the following conditional code:

issue.get("customfield_12345") == null

where customfield_12345 is the field ID of your End Date custom field (see https://confluence.atlassian.com/jirakb/how-to-find-id-for-custom-field-s-744522503.html

yes i am using an old version, with jira 7.0.4 we arent upgrading in the short term, so i used the lined but still giving me error

see attachment:

PF1.PNGPFerror.PNGtransition.PNG

I believe this latest error has nothing to do with the conditional execution script. It's easy to check: just uncheck "only if condition is true".

If you look inside the Jira logfile (atlassian-jira.log), you'll find the full error, accompanied by a stack trace. Can you post them here? My guess is that the two fields are incompatible. What is the type of the End date field?

This would not happen with JMWE 5.x, which handles conversion between incompatible field types (among many other new features). Note that JMWE 5 is fully compatible with Jira 7.0.4...

the post function with out any condition works perfectly

on the other hand:

"End date" is a "date picker" field, while "Due date" is a "date" field

btw i'm using 4.0.4 version of JMWE

Ok, I found the issue. The conditional execution script should be:

issue.get("customfield_11204") == null

You had forgotten the "customfield_"

it's working

haha! thank you, that was desperating

thanks again!

didnt know this: 

You had forgotten the "customfield_"

1 vote
Tarun Sapra Community Leader Mar 06, 2018

As per the docs you have to *return true or false* for the condition to proceed or fail.

The post-function is executed only if the written condition evaluates to true or a Groovy truthyYou can quickly test your written script against any issue using the script tester tool.

https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/73302064/Conditional+execution+using+Groovy+expression

Tarun Sapra Community Leader Mar 06, 2018
if(issue.getCustomFieldValue(end date)) {
return false;
} else {
return true;
}

This should do the trick.

dont know why, but it doesnt work

Tarun Sapra Community Leader Mar 06, 2018

share your complete code

this is it:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("End date");
if (issue.getCustomFieldValue(cf) == null)
if (issue.getCustomFieldValue(cf) == null) {
return true;
} else {
return false;
}

Add the above snippet in your code.

still not working

Shouldn´t the last line use issueObject instead of issue?

Or use the wrapper with issue.get("End date") - but you shouldn´t fix those two...

Hello @David Fischer _Appfire_ ,

Could you please help me here, 
I have added a JMWE postfunction to In progress status (Allowed all statuses to transition to this status) to increament the field value with the ticket transitioned to this status.
But here i want to the increment field value only if the status transitioned from closed or resolved I have used conditional execution as below 
{{ issue.transition.from_status.name == "Closed" }} or {{ issues.transition.from_status.name == "Resolved" }}
But here the value of the field is increasing even if we transitions from any other statuses as well not only from Closed and resolved.

Will you please assist me to pass the condition if last status was Closed or Resolved.

Thanks in advance for your help,

Regards,

Ajay

Hi @Ajay 

I assume you're on Jira Cloud, correct? In that case, the correct conditional execution expression should be:

{{transition.from_status == "Closed" or transition.from_status == "Resolved"}}
Like Ajay likes this

Thank you @David Fischer _Appfire_ ,

You are awesome, this works for me.

Suggest an answer

Log in or Sign up to answer