Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to update the specific Asset object through Automation Rule if field is blank using JSON?

Tiffany Myers April 4, 2024

4/17 UPDATE: I changed the question and will post solutions I found in comments to avoid making this longer.

Original Post:

I am creating a project that when the issue is updated I need to update the Asset object which was created via a post-function.  Using a party planning theme for my example.

Issue Created = OR-44

Issue Fields & Attributes in Object Type:

       Summary (text field) = Anna Beth Collins 6th Birthday Party

       Description (text field) = Mrs. Collins requested Holmes Party Planning services for her daughter's birthday. Initial meeting will be held 2/14/24 with finalization meeting will be held 4/4/24.

       Supplies Required (text field) = Party Hats, Candy, various little toys

       Event Support = (currently empty)

       Initial Ticket Key (text field) = OR-44

       Contract # (text field) (generated during 'Contract Signing' status) = FAVOR-44

       Schema Unique Identifier (Asset object) = (currently empty, but configured to show list of the Initial Ticket Key attribute)

 

Object is created on Object Type 'Parties' through Post-Function of 'Contract Signed' Transition    Object Key = DAO-234432  

 

Wish to Edit/Update the issue with the following:

       Supplies Required = Party Hats, Candy, various little toys, plates, napkins, forks, cake, poppers, 5 tables, 30 chairs, 5 table cloths, balloons, balloon arch, purple sparkly birthday cake candles

 

Few things about the Object schema created:

1. Created attributes to match each field on issue.

2. Contract # is not a unique attribute.

3. Initial Ticket # is a unique attribute.

 

I've tried to copy the Initial Ticket Key to the Schema Unique Identifier field in an automation rule triggered when the fields are edited. Re-fetched the data, then use the Lookup Asset (Insight) objects from AQL (IQL) with ScriptRunner to pull the object info and then use Update Asset with ScriptRunner to update the attribute(s).

AQL/IQL query for the Lookup Asset (Insight) objects from AQL (IQL) with ScriptRunner currently using is: 

objectType = "Parties" and "Initial Ticket Key" = {{issue.Initial Ticket Key}}

 

Update Asset with ScriptRunner for is:

{
"objectTypeId": 217,
"Summary": {{#if(not(equals(issue.customfield_12002,null)))}} "{{issue.customfield_12002}}" {{/}} {{#if(equals(issue.customfield_12002,null))}}null{{/}}
"Description": {{#if(not(equals(issue.customfield_12107,null)))}} "{{issue.customfield_12107}}" {{/}} {{#if(equals(issue.customfield_12107,null))}}null{{/}}
"Supplies Required": {{#if(not(equals(issue.customfield_12005,null)))}} "{{issue.customfield_12005}}" {{/}} {{#if(equals(issue.customfield_12005,null))}}null{{/}}
"Event Support": {{#if(not(equals(issue.customfield_12012,null)))}} "{{issue.customfield_12012}}" {{/}} {{#if(equals(issue.customfield_12012,null))}}null{{/}}
"Initial Ticket Key": {{#if(not(equals(issue.customfield_12013,null)))}} "{{issue.customfield_12013}}" {{/}} {{#if(equals(issue.customfield_12013,null))}}null{{/}}
"Contract #": {{#if(not(equals(issue.customfield_12014,null)))}} "{{issue.customfield_12014}}" {{/}} {{#if(equals(issue.customfield_12014,null))}}null{{/}}
}

 

If there is another way to accomplish this, I am most certainly open to it.

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Tiffany Myers April 17, 2024

Answer to part of this issue:

I created a new Status, EDIT and added the following Post-Functions to the transition from the Current Status to EDIT:

~ After clicking "Add Post-Function", Select the "Assets Post-Function" option.  Click "Add" at the bottom, then Select the "Set the Value of an object attribute with a predefined value" option. 

~For the Source custom field Select the Asset object custom field.  For the Object Type Attribute name Enter the name of the attribute you want to update (You have to make sure it is exactly what you have in Assets).  For the Change value, I entered ${Field Name}.

For the above example:

Source custom field: Schema Unique Identifier

Object Type Attribute name: Summary

Change value: ${Summary}

if "Supplies Required" was set up as an asset field or multi-select field then it would be:

Source custom field: Schema Unique Identifier

Object Type Attribute name: Supplies Required

Change value: ${Supplies Required${0}}

and I paired it with the following automation rule:

Capture.JPG

The JSON for the Update Asset is as follows:

{
"objectKey": {{issue.Schema Unique Identifier.Key.asJsonString}},
"Summary": {{issue.customfield_12002.asJsonString}},
"Event Support": {{issue.customfield_12012.asJsonString}},
"Initial Ticket Key": {{issue.customfield_12013.asJsonString}},
}

However, this will only work if no fields are left blank.

Tiffany Myers April 17, 2024

Have found a work-a-round for the automation rule. So if a field is left blank, it'll still work.

Use the Issue fields condition.

Field: Event Support

Condition: is not empty

Then use the Update Asset 

Code = 

{
"objectKey": {{issue.Schema Unique Identifier.Key.asJsonString}},
"Event Support": {{issue.customfield_12012.asJsonString}}
}

 

This will need to be repeated for each custom field being updated through the automation rule.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events