Using the automation for Jira add to bulk copy the contents of a labels field into an Insight field

Stephen Letch January 18, 2021

Hi all

 

I've replaced a labels field with an Insight multi picker field, but I'd really like to backfill the new field with the contents of the old automatically. Now, the automation for Jira plugin doesn't seem to have decent compatibility in terms of smart values with this, or at least I can't find the right syntax of smart value, so it looks like it'll be a case of using the additional fields JSON area.

 

Does someone have the right format I can try?

 

Thanks

2 answers

1 vote
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2021

@Ravi Sagar _Sparxsys_ that is indeed the right format if you already know the asset ID (in your example 4548_11) you want to add to an issue, but since Stephen's question is about trying to backfill an Insight field based on existing Labels, there's a bit more to it.

The problem that I've found in testing is that Insight does not currently expose an API for doing a "search" by object name. You mentioned this yourself here:

https://community.atlassian.com/t5/Jira-Service-Management/How-to-search-issues-linked-to-an-asset/qaq-p/1566920

I did a little digging though and did discover some interesting things. The Object Schema (project) corresponds to the first 4 digits of an asset ID. Unfortunately this doesn't seem to be stored on the Insight servers, and so you can only figure it out by adding a an asset to an issue and looking at the JSON for an issue, as you described here:

https://community.atlassian.com/t5/Jira-Service-Management/How-to-search-issues-linked-to-an-asset/qaq-p/1566920

If you can get those 4 digits, then I believe the second digit after the underscore corresponds to the Object Schema "key".

Ok, I think we need some pictures.

Here's my Object Schema named Asset (AS):

Screen Shot 2021-01-21 at 2.39.54 PM.png

I have 3 items, AS-1, AS-2, and AS-3.

Now, I added those items to an "Assets" custom field that I created for HELP-14:

Screen Shot 2021-01-21 at 2.47.25 PM.pngScreen Shot 2021-01-21 at 2.45.49 PM.png

And now, following Ravi's advice, I looked at the JSON representation of the HELP-14 fields by going to https://MYHOST.atlassian.net/rest/api/3/issue/HELP-14, and here's what the relevant custom field data looks like:

Screen Shot 2021-01-21 at 2.46.33 PM.png

So you can see that the 7062 appears to be a consistent "project key", and then after the underscore, we have items 1, 2, and 3.

From this issue, it looks like @djenkins figured out that you actually only need to pass the value keypair to set a field value.

So then, what to do?

Well, depending on your number of Labels/Assets, and if each ticket only has one asset, you might be able to brute-force something in Automation by creating a mapping each label to the appropriate asset key.

With those constraints in mind, I created and successfully tested this very automation:

Screen Shot 2021-01-21 at 3.33.04 PM.png

It's a horrible and frankly unworkable solution if you have more than 3 assets or more than one assets per ticket. But I'm sharing it to hopefully give you some ideas of what you're currently up against if you do try and implement something like this.

I wonder if @Ravi Sagar _Sparxsys_ might have a much cleaner way to do this with Scriptrunner, with maybe a nice way to loop through all the labels, and refer to a lookup table to construct the JSON to update the field? If so, I know I'd love to see it. :-}

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2021

Oh, hey, there's an API for searching for objects, and I think it may work by name:

https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Objects#RESTAPI-Objects-Findobjects(Advanced)

Well, that certainly opens up some additional possibilities, maybe using web requests.

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2021

That is a wonderful idea. Let me try using ScriptRunner to do this more efficiently. 😊

Like Darryl Lee likes this
Stephen Letch January 25, 2021

Hi @Ravi Sagar _Sparxsys_ 

 

We also have Scriptrunner, let me know if you've come up with something I can use. I'd be very appreciative as interest in copying the old values to the new field is growing :(

 

also @Darryl Lee you're right, we have hundreds of tickets that have access to around 3500 possible hostnames that I now have objects for in Insight XD

 

thanks

Like Ravi Sagar _Sparxsys_ likes this
Steve Letch February 20, 2021

Sure don't make it easy do they -_- Hopefully now Atlassian owns mindville and codebarrel they'll make the two work together

Steve Letch February 20, 2021

It's so much easier to just send the tickets round a global transition using an Insight post function to fill the field. I suppose regardless of whether you use automation for Jira or the global transition, the issue updated stamp will be updated either way, so the same issue of old tickets potentially showing up on boards would be present, might as well do it the simple way. :(

Like Michaël Monserrat likes this
1 vote
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2021

Hi @Stephen Letch 

Yes you can. Try this format.

{
"fields": {

"customfield_10055": [
{
"appKey": "com.riadalabs.jira.plugins.insight",
"originId": "4548_11",
"serializedOrigin": "com.riadalabs.jira.plugins.insight/4548_11",
"value": "com.riadalabs.jira.plugins.insight/4548_11"
}
]


}
}

I hope it helps.

Ravi 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events