Can I Nest For loops in JMWE?

Drew
Contributor
June 20, 2024

I'm trying to create a system to automatically assign items to a user based on who has the least amount of assigned items. Below I have the post function and the result of the dumps. It seems like the nested for loop is being executed async, because it dumps the result of the nested loop before any of the dumps that should be executed before it.

One thing I'm absolutely sure of is that the user ID being returned to assign does not have 0 items assigned to them.

Am I doing something incorrectly, or are there just limitations I would have to try and work around to get this to function the way I'd like it to?

image.pngimage.png

2 answers

1 accepted

3 votes
Answer accepted
Kuan Yi Ming _ServiceRocket_
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.
June 20, 2024

Hi Drew,

There are no issues with using nested for loops in Nunjucks scripts executed by JMWE.

I would suggest troubleshooting these:

1) Print the output of {{allIcsOpenTasks | length}} and verify the output is greater than 0
2) Check the output of t["fields"]["assignee"]["accountId"] and see if it actually matches the current role member in the first for loop.

Regards
Yi Ming

Drew
Contributor
June 21, 2024

Printing out the length of allIcsOpenTasks lead me right to the answer...

Apparently searchIssues(1000, 0, fields="assignee") doesn't work. It was only returning 10 results.

What I had to do was: searchIssues(maxResults=1000, startAt=0, fields="assignee")

when I added maxResults= I noticed it changed the 1000 to green. It seems like it was seeing 1000 as a string until I added the parameter name.

Thank you!!

1 vote
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.
June 21, 2024

Hi @Drew 

are you sure this is the exact code you're testing? On the script screenshot I don't see the words "Current user being checked".

Also, don't use the "===" operator but "==". And you don't need "| dump(2)" to print a string. Finally, the whole point of templating is to avoid having to build strings, so you can do something like:

Current task assigned to user: {{t.fields.assignee.accountId}} Current task assigned user: {{currentAccountIdTaskCount}}

Can you share the full script as text (inside a  "code block" format) instead of a screenshot?

Drew
Contributor
June 21, 2024

Thanks for looking this over and for your suggestions David! Trying out what Kuan suggested lead me to the answer so I'm all set

Suggest an answer

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

Atlassian Community Events