I’m trying to build an automation rule in Jira Cloud that removes an object attribute (application) from a multi-object attribute (field type: Assets object attribute) in the Employees object type.
Schema: Staff
Object Type: Employees
Attribute: Applications (multi-object, references the Applications object type)
We already have a working rule that adds applications using a structure like:
Now, I want to remove a specific Application (e.g., APP-17) from an employee’s list of Applications when a sub-task is created (used for access revocation).
Using variables allApps, filteredApps and appToRemove:
appToRemove
{{issue.customfield_10629.key}}
allApps
{{object.Applications.key.join(",")}}
filteredApps
{{allApps.replace(", ",",")
.replace("[","")
.replace("]","")
.replace(appToRemove, "")
.replace(",,", ",")
.trim(",")}}
Then passing it into the Edit Object action like this:
[ {{#filteredApps}} { "key": "{{.}}" }{{^last}},{{/}} {{/filteredApps}} ]
But it doesn't work.. any help is appreciated.
Fabio
Without seeing your complete rule and the audit log details...
Have you tried writing to the log the incremental pieces of that smart value expression, confirming each step parses as you expect? For example:
appToRemove: >>{{appToRemove}}<<
allApps: >>{{allApps}}<<
filteredApps: >>{{filteredApps}}<<
And then the pieces of the parsing:
allApps.replace(", ",","): >>{{allApps.replace(", ",",")}}<<
allApps.replace(", ",",").replace("[",""): >>{{allApps.replace(", ",",").replace("[","")}}<<
...
Please note the extra >> and << characters to help confirm the exact contents.
Also, as the allApps variable apparently contains a nested list (which is why you are removing the square brackets), perhaps try adding the flatten function instead:
{{object.Applications.key.flatten.join(",")}}
Kind regards,
Bill
Hi Bill,
thanks for your answer.. here is the output of the action log:
allApps: STAF-17,STAF-16 >> {{object.Applications.key.join(",")}} <<
appToRemove: STAF-17 >> {{issue.customfield_10629.key}} <<
Final:
The following Edit Object action wipes all contents but I would like to just remove a single app.
{{allApps.replace(", ",",").replace("[","").replace("]","").replace(appToRemove, "").replace(",,", ",").trim(",").split(",").distinct}}
By the way, I'm not using nested lists as per above example.
Any pointers are appreciated.
Thanks
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for testing those expressions, @Fabio Cerullo
As you have no nested lists, the replace functions to remove the brackets should not be necessary. Let's try a different expression to see what happens...initially just writing the result to the audit log:
{{allApps.replace(appToRemove, "").split(",").trim.match("(.++)").distinct}}
What that does is:
Please try that one, and if it works, you may add iteration to build your dynamic JSON expression.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bill,
Thanks for the input.
I've tried split/filter but it is not playing nicely.
What I've done and I (almost) got it working is as follows:
appToRemove >> {{issue.customfield_10629.key}}
allApps >> {{object.Applications.key.join(",")}}
cleanedAppsOne >> {{allApps.replace(appToRemove, "")}}
cleanedAppsTwo >> {{cleanedAppsOne.replace(",,", ",").replace("^,", "").replace(",$", "")}}
trimmedApps >> {{cleanedAppsTwo.trim(",")}}
uniqueApps >> {{trimmedApps.distinct}}
Here is the action log:
Variable Debug Log: appToRemove: STAF-17 allApps: STAF-17,STAF-16 cleanedAppsOne: ,STAF-16 cleanedAppsTwo: ,STAF-16 trimmedApps: uniqueApps:
As you could see, the trailing comma never goes away and that cascades into an empy value.
Any help is appreciated.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Something seems incorrect if that expression does not work. This is one reason posting images of rules, actions, and the audit log helps to confirm we are aligned on what is being tried. Regardless...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bill,
Thanks for your help.
I went back to your example and the output of
{{allApps.replace(appToRemove, "").split(",").trim.match("(.++)").distinct}}
is exactly the application that remains after the appToRemove is removed.
So it is working as expected.. now, you mentioned something about adding iteration to build your dynamic JSON expression. I believe that should go in the Edit Object action?
{{#filteredAppKeys}} >> is the expression you provided me above.
I've tried the following in the Edit Object but it is not working:
[ {{#filteredAppKeys}} { "key": "{{.}}" }{{^last}},{{/}} {{/filteredAppKeys}} ]
Can you please guide me on how to do that?
Thanks,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If your variable filteredAppKeys contains a comma-delimited list of values, it needs to be split before iteration will work:
[ {{#filteredAppKeys.split(",")}} { "key": "{{.}}" }{{^last}},{{/}} {{/}} ]
FYI...I am not currently using assets in my test site and so cannot experiment with that expression for an object update.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Bill,
{{filteredAppKeys}} contains STAF-16
But it is giving me an error when trying the expression above.
Attribute value is not valid on Objects
STAF-693 (Applications = [ { "key": "STAF-16" } ])
Unable to update objects
any pointers are really appreciated.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bill,
Thanks a LOT for your help.
That smart variable that you provided me was a life saver.
I've finally managed to edit the object successfully... here is the syntax:
{{filteredAppKeys.replace(", ",",").replace("[","").replace("]","").split(",").distinct}}
Kind regards,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.