Clearing a Assets attribute via Automation ? error when attribute is already empty (Feature/Bug)
Asked by Rodney Dsouza _Atlassian Certified Expert_:

I noticed that if you use the "Edit Object" action in an Automation to set fields, that works great but if you are trying to clear a field you can into an Error message (Automation Rule failed).

The scenario is that you use the "Edit Object" action and you want to clear an attribute. So, you pick that attribute from the dropdown list and then instead of putting in a value, you leave it blank. You can see that the field is blank, it says "the attribute will be cleared", and so that is promising.

It works great when the attribute is already set to a value in the object. But when the attribute is already empty you will see messages in the rule log like "Objects were skipped" and "Error updating Object(s)" and overall Automation Rule will also fail.

I think the behavior should be that it not error.

The workaround available for me is that I check the value of the existing attribute in JSM Assets and only then "set" (clear) the value. Since Automation does not allow IF blocks within the "For AQL" I don't believe you will be able to do this for multiple attributes.

I had tried setting an empty expression e.g. {{}} etc. and that did not seem to work.

Let me know your thoughts if you disagree that this is a Bug/Feature, or if you found this useful.

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


Answers:
author: Bill Sheboy
body: Hi [@Rodney Dsouza _Atlassian Certified Expert_](/t5/user/viewprofilepage/user-id/1543949)

I hypothesize this happens because empty assets may not exist in the dynamic storage, and so trying to set the value to empty raises the error.

Without seeing your complete rule for context...

Although the if / else condition block is not available inside of branches, other conditions are available. Have you tried using a condition to selectively clear the field at the end of the branch? That would eliminate the need for the if / else.

Kind regards,  
Bill

comments: author: Rodney Dsouza _Atlassian Certified Expert_
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Thanks for your input.

Not sure what you mean by "empty assets" - in the scenario the object exists, it's one or more attributes within that object that may be not-set.

"Have you tried using a condition to selectively clear the field at the end of the branch? That would eliminate the need for the if / else." Assuming that "field" you mean "attribute" (that is what they are called in JSM Assets), then that is exactly what I did, but I was fortunate that in my particular data scenario there is only 1 possible attribute that could be empty. If I had 2 or more possibly empty attributes, the first non-empty attribute would cause the rest of the branch to not run.


author: Bill Sheboy
body: Again without knowing the internal implementation of assets, I suspect the structure / configuration of assets is stored separately from the attribute contents, and so the REST API may not correctly handle clearing an attribute's content that is already empty: the configuration exists but the content does not...leading to the error you observed.

As you appear to be a site admin for your Jira instance, you could submit a ticket to Atlassian Support to learn what they think: <https://support.atlassian.com/contact/#/>

Regarding your scenario of 2, or more, possibly empty attributes, you might try using created variables and inline conditions to build dynamic JSON for updates. However I have not seen much guidance on JSON updates for assets from rules, so asking Atlassian Support may help there also.


author: Josh Schoenick
body: It is bizarre. I deleted the object and created a new one, now I can clear the fields.


author: Rodney Dsouza _Atlassian Certified Expert_
body: Thanks [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) and [@Josh Schoenick](/t5/user/viewprofilepage/user-id/3679460) , it seems like this issue has been reported/recorded before at <https://jira.atlassian.com/browse/JSDCLOUD-13612> and <https://jira.atlassian.com/browse/JSDCLOUD-11236>

When I had previously searched the Internet, I had not found those Bugs.


author: Josh Schoenick
body: I'd consider this a bug


author: Rodney Dsouza _Atlassian Certified Expert_
body: A workaround that might be acceptable to some is to use a conditional like this: {{if(CellPhone.isEmpty(),"None",CellPhone)}}

This assumes it is okay for your scenario to put in the string "None" as a placeholder for empty value.

Note that in the above example CellPhone is a variable that is a string.

I believe for an array you would use isEmpty without the parentheses. And in other cases you check for null with something like {{if(equals(variable,NULL),"None",variable)}}

This type of conditional is available with Cloud, not sure about Server/DC. Documentation here: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/>


Tags: cloud

jira-cloud