Rule builder code syntax not working, what am i doing wrong?
Asked by MarcelMeeuwissen:

Hey guys,

We are currently implementing an ISO 27001:2022 ISMS in JIRA + Confluence. We only have one issue left that has to do with automation in JIRA, but for the love of me i can't figure out how to fix it. I've looked at the documentation and asked chatgpt but i cannot find the answer. Maybe someone here can?

I have two custom fields in my ISO 27001 issues, one is named "Due Date (ISO)" and the other is named "Check Frequency (ISO)". If an issue that has both these values filled in gets closed or resolved, i want a new issue cloned and the "Due Date (ISO)" set to a new date (e.g. a month, quarter, year, etc later).   

So for example, Due Date (ISO) is 31/12/2024. Check Frequency (ISO) is 'Yearly'. I want the cloned issue to be the same issue but the Due Date (ISO) should be set to 31/12/2025.  

The conditions (fields not empty) work and the automation clones the issue just fine, but the Due Date (ISO) is emptied. What am i doing wrong?

You can find the screenshot and then the code underneath the screenshot. In the 'fields to set' pulldown, only "Due Date (ISO)" is selected.

Thanks in advance!

![Screenshot 2024-09-03 at 11.15.10.png](https://community.atlassian.com/t5/image/serverpage/image-id/345214i0ABCC8F19DA256FF/image-size/large?v=v2&px=999 "Screenshot 2024-09-03 at 11.15.10.png")

```
{{if(equals(issue.Check Frequency (ISO), "Monthly"), issue.Due Date (ISO).plusMonths(1), if(equals(issue.Check Frequency (ISO), "Quarterly"), issue.Due Date (ISO).plusMonths(3), if(equals(issue.Check Frequency (ISO), "Yearly"), issue.Due Date (ISO).plusMonths(12), if(equals(issue.Check Frequency (ISO), "Two-yearly"), issue.Due Date (ISO).plusMonths(24), if(equals(issue.Check Frequency (ISO), "Three-yearly"), issue.Due Date (ISO).plusMonths(36))))))}}
```


Answers:
author: Marc - Devoteam
body: Hi [@MarcelMeeuwissen](/t5/user/viewprofilepage/user-id/1090546)

A field value set on using smart values can only contain a value, based on the smart value.

You can't use IF/ELSE statements in setting a field value.

That's where you need the IF/ELSE condition in the rule


author: Jovin
body: Hey [@MarcelMeeuwissen](/t5/user/viewprofilepage/user-id/1090546)

I would suggest breaking this out into the Automation Actions for "IF/ELSE", it makes it much easier to read and maintain.

This IF/ELSE assumes you've already created the issue, and is now modifying the due dates accordingly.

* IF Issue field value
  * Field: Check Frequency (ISO)
  * Condition: Equals
  * Value: Monthly
  * THEN: Action: Edit Issue
    * Field: Due Date (ISO)
    * Value: {{issue.Due Date (ISO).plusMonths(1)}}
* ELSE Issue field value
  * Value: Quarterly
  * THEN: Action Edit Issue
    * Value: {{issue.Due Date (ISO).plusMonths(3)}}
* etc. etc.

comments: author: MarcelMeeuwissen
body: Hi Jovin, not to sound ungrateful but this was exactly what i was trying when you replied to my post - so i'm happy to hear you confirm this is a better idea. Thank you for your efforts. Sadly i did wish to understand why the code doesn't work, but there are just not enough resources on this to understand it, i guess.


Tags: automation

cloud

cloud-automation

jira-cloud