postfunction problem with conditional with JMWE

marçal martorell March 6, 2018

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

5 answers

1 accepted

3 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2018

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

marçal martorell March 7, 2018

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 7, 2018

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...

marçal martorell March 7, 2018

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

marçal martorell March 7, 2018

btw i'm using 4.0.4 version of JMWE

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 7, 2018

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

issue.get("customfield_11204") == null

You had forgotten the "customfield_"

marçal martorell March 7, 2018

it's working

haha! thank you, that was desperating

thanks again!

marçal martorell March 7, 2018

didnt know this: 

You had forgotten the "customfield_"

1 vote
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2018
if(issue.getCustomFieldValue(end date)) {
return false;
} else {
return true;
}

This should do the trick.

marçal martorell March 6, 2018

dont know why, but it doesnt work

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2018

share your complete code

marçal martorell March 7, 2018

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)
Tarun Sapra March 7, 2018
if (issue.getCustomFieldValue(cf) == null) {
return true;
} else {
return false;
}

Add the above snippet in your code.

marçal martorell March 7, 2018

still not working

1 vote
Thomas Heidenreich
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.
March 6, 2018

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...

marçal martorell March 6, 2018

not working

0 votes
Atlassian Learner October 18, 2022

Hi @David Fischer 

Trust you are doing well!

I'm here again for you help.

I have a requirement to make with Date and Time field on Request forms.

The Date should be mandatory and Time should be optinal for Date and Time field.

I have used field required validator with these conditions.

!!(issue.customfield_10042 ? new Date(issue.customfield_10042) : null)
! issue.customfield_10042

 But both didn't go well. 

Hope you have the solution for It.

Thanks In advance for the help,

Regards,

Ajay

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2022

Hi @Atlassian Learner ,

Is this a regular Date/Time Picker custom field? In that case, I don't believe what you're trying to achieve is possible.

Atlassian Learner October 18, 2022

Thanks  @David Fischer for your response.

Yes, it Date/time picker custom field! we need only date should be mandatory in the create screen.

Thanks again.

0 votes
Atlassian Learner September 7, 2022

Hello @David Fischer ,

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2022

Hi @Atlassian Learner 

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 Atlassian Learner likes this
Atlassian Learner September 7, 2022

Thank you @David Fischer ,

You are awesome, this works for me.

Suggest an answer

Log in or Sign up to answer