Forums

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

In JMWE build your own script post function Enable to execute Nunjucks script

Umar Maroof
Contributor
March 29, 2023

Hello everyone 

Actually I am trying to change my original estimate values based on custom field value Like if we have 10H in original estimate and we enter 50 in number field it will subtract the 50% from the original estimate then it become 5H when specific transit happen for that I bulid a post function in JMWE but it give error 

 

{%- if issue.fields.customfield_10185 is defined and issue.fields.timeoriginalestimate is defined -%}
{%- set customFieldValue = issue.fields.customfield_10185.value %}
{%- set originalEstimate = issue.fields.timeoriginalestimate.value %}
{%- set percent = customFieldValue / 100 %}
{%- set newEstimateSeconds = originalEstimate - (originalEstimate * percent) %}
{%- set newEstimateHours = newEstimateSeconds / 3600 %}
{%- set update_params = {"timeoriginalestimate": {"value": newEstimateHours}}-%}
{{- issue.updateIssue(update_params) -}}
{%- endif -%}

Following is the error:

Message:
(string) [Line 7, Column 23]
  Error: Unable to call `issue["updateIssue"]`, which is undefined or falsey

 

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
March 30, 2023

Hi @Umar Maroof ,

Build-your-own post functions are meant to use the Jira REST API directly to make changes to Jira. You cannot update fields the way you did.

Also, there are a few errors in your script. For example, if customfield_10185 is a Number field, its value is directly issue.fields.customfield_10185, not issue.fields.customfield_10185.value (which would be for a Select-type field). Same for timeoriginalestimate. You can see all this on the "Issue Fields" help tab below the editor.

Furthermore, the timeoriginalestimate field expects a number of seconds, not hours.

Instead, you should use a Set Issue Fields post function, select the Original Estimate as the field to set, and for the value use the following script:

{%- if issue.fields.customfield_10185 is defined and issue.fields.timeoriginalestimate is defined -%}
{%- set customFieldValue = issue.fields.customfield_10185 -%}
{%- set originalEstimate = issue.fields.timeoriginalestimate -%}
{%- set percent = customFieldValue / 100 -%}
{%- set newEstimateSeconds = originalEstimate - (originalEstimate * percent) -%}
{{- newEstimateSeconds -}}
{%- endif -%}

and you should select the "Ignore empty value" option to avoid modifying the Original Estimate if one of the fields is empty.

Umar Maroof
Contributor
March 30, 2023

@David Fischer Thanks it work perfectly for me 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events