I am working with Jira/JSM DC 9.12.x
We need to set a new Assets Object custom field that has been added to issues. My first thought was to use an Automation Rule. We have ScriptRunner, so we have the Lookup Assets action.
I am successful using Automation to get the Asset I want, and the issue I want to update. I have not yet been able to figure how to actually update the Assets Object field in the issue.
The field is a single-select Assets Object field.
I found a post about doing this for Cloud. I've not found anything explicit for this for Data Center.
I am open to doing scripting instead. I thought it would be simple to do in an Automation rule.
Below are my rule and the log for running the rule. For testing purposes I have limited the scope to one issue that needs updating.
If I manually set the Assets Object field in the issue and then use /rest/api/2/search to output the issue data, it looks like this:
{
"issues": [
{
"key": my-issue-key,
"fields": {
"customfield_12345": [
"Name of object (object-key)"
]
}
}
]
}
Why we need to do this:
1. We had a bunch of issues that identified things that we are now converting to Asset Objects.
2. There are a bunch of issues Linked to the issues-that-are-becoming-Asset-Objects.
3. We have added an Assets Object custom field to those other issue types.
4. We want to now update the Assets Object custom field in those other issue types to relate them to the new Asset Objects so that we can, ultimately, archive or delete the original issues-that-are-becoming-Asset-Objects.
5. To facilitate this, when converting the issues to Asset Objects we have a field in the Object for the original issue key.
First the disclaimers: I am not using DC or Assets, and so my suggestions are based on what I know about rules, in general. With that out of the way...
The JSON expression you are showing uses the asJsonObject() function. As written, I expect that to produce a result like this:
{
"fields": {
"Site": "{ "key": "SB-1136017" }"
}
}
Which will fail due to the nested double-quotation marks.
What is the type of your field, "Site"? That earlier article was using the JSON function to help build an array of values, but that would not work for the syntax you show.
The other possible thing to check is timing problems with Asset information and the advanced edit with JSON. I have observed problems where the JSON validation can occur (and fail) before the dynamic expression can fully parse. (The same thing happens with the Send Web Request action for URLs and the request body.)
I recommend pre-building the JSON into a created variable first, and then using that variable in the advanced edit. This will ensure it fully evaluates before use. (It can also be logged to check the validity of the JSON in an external tool by copy-and-pasting the log text there.)
Kind regards,
Bill
Thank you for the suggestions @Bill Sheboy .
The Site field is an Assets Object custom field.
What I was hoping to get as an answer was an actual example of how somebody successfully set an Assets Object (single selection) field through Automation on Jira DC, with bonus points if they did it after getting the object from a Lookup Assets action. The Adaptavist documentation doesn't have an example of this, and I haven't been able to find any examples specific to DC.
But I'll see if I can make more progress with the suggestions you've provided. Thanks, again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries, and based on the hard-coded example you tried, perhaps try this:
{
"fields": {
"Site": {{lookupAssets.objectKey.asJsonObjectArray("key")}}
}
}
That function will add the array syntax and handle multiple values when they are present.
And if that does not work, try the "update" with an "add" operation rather than "fields" for a replacement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I haven't had a chance to work on this, but my colleagues gave me the following tips also.
it looks like you're trying to set the asset field using the ID of the object you looked up, so you'll want to make sure that the Asset custom field is configured to locate the object using the object key ID. A lot of times this field is set to locate based on the primary label or title of the object, you can configure the field to locate based on multiple attributes.
The above is true; I don't have the field including the Key of the object. So I think that will be the first thing I test - updating the configuration of the field.
A reference with Automation rules, way at the bottom of the page:
https://confluence.atlassian.com/automation0902/advanced-field-editing-using-json-1431247626.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This was the final solution:
I did not need to add Key to the Assets Custom field configuration.
The smart value to get the object key did not need to be so complex.
Changing the Advanced Editing to this worked:
{
"fields": {
"customfield_XXXXX": [{"key" : "{{lookupAssets.objectKey}}"}]
}
}
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.