Forums

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

how to combine "Jira expression" and "Nunjucks script"

Christian Schneider
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.
January 20, 2023

Dear community,

I am currently migrating from Server to Cloud and I do have some groovy based post functions, which I need to translate into Nunjucks.

I need to read some values from a custom field and use it in nunjucks, to do some if/else logic. How do I do that?

 

 

I have the Repeating Issue App by codedoers. In Server, there is a specific field with the "Next occurrence", in Cloud this field is missing. I have asked support and they told me, that I can access the information via "com.codedoers.jira.repeating-issues:task".

I am using the JMWE-app for development.

 

Jira expression

If I use a "Jira expression", I can get the needed information:

issue.properties['com.codedoers.jira.repeating-issues:task']

results in

Your Jira expression ran successfully
Result:


"Object":{
"updatedTime":
"2023-01-20T07:11:47Z"
"updatedBy":
"60815edd9c4625006b35804a"
"action":
"WorkflowStepTask"
"lastExecutionErrors":[]
"recurrenceRules":[
0:"RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=20"
]
"nextOccurrenceTime":
"2023-02-20T06:41:54Z"
}

 

issue.properties['com.codedoers.jira.repeating-issues:task'].recurrenceRules[0]

results in

Your Jira expression ran successfully
Result:
"RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=20"

 

Nunjucks scripts

If I try to use this in Nunjucks expression, I am not getting anything back.

{{ issue.properties['com.codedoers.jira.repeating-issues:task'].recurrenceRules[0] }}

It just says "Your template ran successfully". No result.

 

Any help is very much appreciated.

Chris

 

1 answer

1 accepted

0 votes
Answer accepted
Christian Schneider
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.
January 20, 2023

This is, how to get the data:

{{ issue | issueProperty("com.codedoers.jira.repeating-issues:task") | dump(2) }}

{{ issue | issueProperty("com.codedoers.jira.repeating-issues:task") | field("nextOccurrenceTime") }}

{{ issue | issueProperty("com.codedoers.jira.repeating-issues:task") | field("recurrenceRules") }}

 

the last will return

RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=20

 

How do I extract "MONTHLY" from this?

Or how do I test, if this string contains "MONTHLY"?

Fabian Dengel
Contributor
January 20, 2023

Hey @Christian Schneider 

I gave this a go as well and seems you need to convert the output to a simple string (looks like the "dump" creates an object, which does not seem to play nicely with the "IN" operator we need to check for the substring).

see example for MONTHLY below with the string conversion added at the end.

Keep in mind that

a) I am not a dev so take my approach with a grain of salt :) and

b) the search is case-sensitive (see here for a workaround: How to check whether the substring is present in a string in Nunjucks Template - Stack Overflow)

Fingers crossed it works for your case and kind regards
Fabian


{% if 'MONTHLY' in issue | issueProperty("com.codedoers.jira.repeating-issues:task") | field("recurrenceRules") | string %}
true
{% else %}
false
{% endif %}
Christian Schneider
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.
January 25, 2023

This is, how you do it:

{% set res = issue | issueProperty("com.codedoers.jira.repeating-issues:task") %}
{% set nOTime = res | field("nextOccurrenceTime") %}
nOTime: {{ nOTime }}
{% set recurrenceRules = res | field("recurrenceRules") %}
{% if recurrenceRules %}
{% set rR = recurrenceRules.toString() %}
{% set freq = rR.match(r/FREQ=(\w{0,50})/)[1] %}
freq: {{ freq }}
{% set interval = rR.match(r/INTERVAL=(\w{0,50})/)[1] %}
interval: {{ interval }}
{% endif %}

 

full credit to @Suprija Sirikonda _Appfire_ 

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events