Automation Rule to null check custom field
Asked by mnd:

I have a custom field field in Jira that can look like this:

```
"customfield_10130": [
  {
    "self": "https://<jira>/jira/rest/api/2/customFieldOption/10251",
    "value": "Yes",
    "id": "10251"
  }
]
```

When this value is not set, it looks like this:

```
"customfield_10130": null
```

I'm trying to compare this custom field when it's null, and cannot ever get any type of information from it. I've used all sorts of smart values - both what I've found in the documentation, and guessed at, they include:

* {{issue.customfield_10130.isEmpty()}}
* {{issue.customfield_10130.length()}}
* {{issue.customfield_10130.size}}
* {{issue.customfield_10130.isNull()}}
* {{issue.customfield_10130 = null}}

None of these provide anything I can use in a comparison. Any ideas how to compare this empty/null custom field?


Answers:
author: Ryan Cabanas
body: I've had success using an "Advanced compare condition" too like this.

![2021-11-08_12-12-13.png](https://community.atlassian.com/t5/image/serverpage/image-id/168387iAE813AFC20EE09DA/image-size/large?v=v2&px=999 "2021-11-08_12-12-13.png")

In my example here, I'm checking the **{{issue.timespent}}** smart value for **null**.

comments: author: sciencecovskij
body: Couldn't believe it - but works. Incredible...


author: Kevin Ultsh
body: Thank you for this! Just worked for me as well.


author: Nic Thiele
body: Thank you. This worked for me where isEmpty did not. I am setting *additional fields*with an automation step.

```
{
    "fields": {
        "customfield_13421": {{#if(equals(triggerIssue.customfield_13421, null))}}null{{/}}{{triggerIssue.customfield_13421.asJsonObjectArray("id")}}
    }
}
```


author: Somasekhar Reddy Palli
body: will this expression work to check if a page is a subpage or parent?

{{#if(equals(page.parent.id, NULL))}}TRUE{{/}}


author: Benoit
body: I still didn't get anything being able to detect null value in automation.

The does not equal or not matching, is always true no matter what is the value set, not set or set to None for custom field drop down.

Is someone have a solution for a drop down custom field?


author: Mircea Pop
body: Hi,

I'm using **Advanced compare condition**with regular expressions. For the below example I check if a field from the issue's epic is not empty.

![Screenshot 2021-03-11 at 20.10.03.png](https://community.atlassian.com/t5/image/serverpage/image-id/134118i56C8CEF6961BBA77/image-size/large?v=v2&px=999 "Screenshot 2021-03-11 at 20.10.03.png")

For your case would be a similar check

![Screenshot 2021-03-11 at 20.11.16.png](https://community.atlassian.com/t5/image/serverpage/image-id/134119iDCC990052A3FE731/image-size/large?v=v2&px=999 "Screenshot 2021-03-11 at 20.11.16.png")


author: Tom Williams
body: Hi [@mnd](/t5/user/viewprofilepage/user-id/538133) ,

Tried using the "Advanced compare condition"?

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

comments: author: mnd
body: [@Tom Williams](/t5/user/viewprofilepage/user-id/3514085) thanks for the response! (Apologies for my delayed response). When I tested this, the "if" check always passes, regardless of whether the field is actually empty or not.


author: Tom Williams
body: [@mnd](/t5/user/viewprofilepage/user-id/538133) - strange this works for me in my rules. You could use the log action to capture what the rule is picking up when you expect it to be empty.


author: Jeff Turner
body: I get the same thing as [@mnd](/t5/user/viewprofilepage/user-id/538133). I'm using a custom date field which might be the issue. All I want to do is set the date to today if it hasn't already been set. Why does this have to be so difficult.  

I just tried this with a JQL check as well "Being Developed Date\[Time stamp\]" is EMPTY and when I test the JQL it tests just fine but when it comes to actually working, I just get this in the log \`The following issues did not match the condition:\`  

After walking away from this and taking a breath. I realized I just had the if check in the wrong place. I was able to get it working with the jql check. YAY!!!!


author: Benoit
body: do you have a screen shoot? I can't make it work.

Thanks


author: Hana Ku?erov?
body: Hi [@mnd](/t5/user/viewprofilepage/user-id/538133) ,

would you please provide us more information - how does your automation rule like (triggers, conditions, actions - what do you need to do, if your custom field is empty or not empty...)?

Is it server or cloud verion of automation for Jira?

Thank you.

comments: author: mnd
body: Hi [@Hana Ku?erov?](/t5/user/viewprofilepage/user-id/1226304), thanks for the response. I'll try to explain it more thoroughly below.

Just for more context, this is related to another question I posted - trying to understand either situation to come to a solution. The other question is posted [here](https://community.atlassian.com/t5/Automation-questions/Creating-Automation-Rule-to-synchronize-fields-between-issue-and/qaq-p/1533040).

I'm demonstrating the behavior in two automation rules - but hoping there is a better way, which combines them into a single rule.

In this project there is a sub-task called "Release Notes". There is also a custom field called "Primary QA" that exists on both the Release Note sub-task, and the parent issue. I would like to make sure that the "Primary QA" value of the parent is always in-sync with the "Primary QA" field in the "Release Notes" sub-task. These are the two scenarios I'm trying to make work.

1. When the "Primary QA" field is changed in the parent issue, the change is reflected in any existing "Release Notes" sub-tasks. (Currently working with the "Field Sync: Primary QA" automation rule below)
2. When a "Release Note" sub-task is created for the parent issue, the new sub-task's "Primary QA" matches what is in the parent issue. (Currently working in "Field Sync: Primary QA 2" automation rule. Attempted as the second branch chain in "Field Sync: Primary QA" automation rule).

It seems I can trigger on when a field is changed, or an issue is created, but if I could trigger on both states, then it seems like I could work through the logic in the automation rule.

Any suggestions would be appreciated. Thanks for your time!

![Field Sync - Primary QA 1.png](https://community.atlassian.com/t5/image/serverpage/image-id/118321i396F33FCAE1184B4/image-dimensions/223x605?v=v2 "Field Sync - Primary QA 1.png")![Field Sync - Primary QA 2.png](https://community.atlassian.com/t5/image/serverpage/image-id/118320iBADC15708383B0D4/image-dimensions/246x381?v=v2 "Field Sync - Primary QA 2.png")


author: Hana Ku?erov?
body: Hi [@mnd](/t5/user/viewprofilepage/user-id/538133) ,

thank you for the clarification. I've posted the answer to your other question.

The only information I'm missing is, why do you need such comparison?

Is customfield_10130 your Primary QA custom field?


Tags: jira-software