How to use smart value in if condition for automation
Asked by Nicolas Courvoisier:

Hello,

I would like to have automation when a pull request is created, the status is changed to "In Review". However, that should not happen if it's only draft pull request. It can be identified with a pull request title containing "Draft". I also exclude tickets of type "Incident" which have a different workflow.

No add-on tool possible.

The following automation rule returns "some errors" but only details "no actions were performed". Can someone please help me?

![ShareX_Nicolas_ExaltedBrownbutterfly.png](/t5/image/serverpage/image-id/281965i271FD4D2E822490C/image-size/large?v=v2&px=999 "ShareX_Nicolas_ExaltedBrownbutterfly.png")


Answers:
author: Bill Sheboy
body: Hi [@Nicolas Courvoisier](/t5/user/viewprofilepage/user-id/4269216)

Would you please post an image of the audit log details showing the rule execution, including one with the error? That may provide some context to understand this symptom.

And as the rule appears longer than what you show, could you also post an image of the complete rule, ideally in a single image?

Thanks!

Kind regards,  
Bill

comments: author: Nicolas Courvoisier
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Here is below the audit log.![ShareX_Nicolas_SmoothAtlanticspadefish.png](https://community.atlassian.com/t5/image/serverpage/image-id/282195iBFDC82502B575763/image-size/large?v=v2&px=999 "ShareX_Nicolas_SmoothAtlanticspadefish.png")

There is nothing more for the rule at the bottom of screen.

Thank you, best regards

Nicolas


author: Bill Sheboy
body: Thanks for that information...and I am fairly confident your conditions may be the problem. If you post images of your condition details I can confirm that.

What you show leads me to believe you have this in a condition:

{{pullRequest.title.toLowerCase().indexOf("draft")\>0}}

That is invalid, as the greater-than sign is not valid in that expression.

There are at least 2 ways to test that condition:

* use an advanced compare condition and test
  * first value: {{pullRequest.title.toLowerCase().indexOf("draft")}}
  * condition: greater than
  * second value: -1
* use an advanced compare condition, with an [inline, greater-than](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Greater-than) test
  * first value: {{pullRequest.title.toLowerCase().indexOf("draft").gt(-1)}}
  * condition: equals
  * second value: true


author: Nicolas Courvoisier
body: Hello

Please find below my condition, I used indeed a simple "JQL condition":

![ShareX_Nicolas_RunnyVixen.png](https://community.atlassian.com/t5/image/serverpage/image-id/282227iD301968137052B1E/image-size/large?v=v2&px=999 "ShareX_Nicolas_RunnyVixen.png")

I switched to "Advanced compare condition" with your 1st change:

* first value: {{pullRequest.title.toLowerCase().indexOf("draft")}}
* condition: greater than
* second value: 0

and am waiting for the next PR created. I keep you posted. Many thanks.


author: Nicolas Courvoisier
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) it works like a charm now.

Many thanks for your precious help!


author: Nicolas Courvoisier
body: Hello,

Unfortunately, the positive match condition with the PR title did not work. This couldn't be tested previously (requires a PR with "draft" in title).

As you can see PR contains the word "DRAFT" but the if condition isn't matched.

Any idea? Thank you

![ShareX_Nicolas_HotNaga.png](https://community.atlassian.com/t5/image/serverpage/image-id/283620i2BEBE7986D92307F/image-size/large?v=v2&px=999 "ShareX_Nicolas_HotNaga.png")


author: Bill Sheboy
body: My apologies, Nicolas...It appears indexOf() returns a 0-based value. That is, the first position is at 0. When nothing is found, it returns -1.

And so the second value in that condition should be changed to -1 to help when draft is in the first position.

I will update the earlier posts also.


author: Nicolas Courvoisier
body: Ok super, I have modified it. Many thanks again for your support. Let's wait for a draft PR to confirm.


author: Nicolas Courvoisier
body: It has worked well :)

Again thanks [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)


author: suha_shakaa
body: Hello

I tried this and it didn't work for me unfortunately the status remains unchanged and the audit log give me this. Can someone help please![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/336968iB6B58CA24F57B6EB/image-size/large?v=v2&px=999 "image.png")


author: Bill Sheboy
body: Hi [@suha_shakaa](/t5/user/viewprofilepage/user-id/5549102) -- Welcome to the Atlassian Community!

As this is an older thread, I recommend creating a new question and perhaps add a link back to this one. That will ensure the maximum number of people see it to offer suggestions.

When you post your new question, please include:

* what problem are you trying to solve; that is, "why do this"
* an image of your complete automation rule, in one image file
* images of any relevant trigger, actions, branches, or conditions
* an image of the audit log details showing the rule execution
* explain what is not working as you expected, and how you know that

Those will provide context for the community to offer help. Thanks!

Kind regards,  
Bill


author: suha_shakaa
body: Thanks Bill

I have posted a new question here

<https://community.atlassian.com/t5/Automation-questions/Automation-with-Github-How-to-create-a-rule-based-on-a-Draft/qaq-p/2761618>


Tags: cloud

jira-software

jira-software-cloud