Using the automation for Jira add to bulk copy the contents of a labels field into an Insight field
Asked by Stephen Letch:

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


Answers:
author: Darryl Lee
body: [@Ravi Sagar _Sparxsys_](/t5/user/viewprofilepage/user-id/853596) 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](https://community.atlassian.com/t5/image/serverpage/image-id/126772i9BBD05D9CC7733B1/image-dimensions/371x242?v=v2 "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.png](https://community.atlassian.com/t5/image/serverpage/image-id/126773i2239D0A92F8C9B5F/image-dimensions/364x310?v=v2 "Screen Shot 2021-01-21 at 2.47.25 PM.png")![Screen Shot 2021-01-21 at 2.45.49 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/126774i1708FE19AE49008A/image-dimensions/164x116?v=v2 "Screen 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](https://community.atlassian.com/t5/image/serverpage/image-id/126775i142146B4BAE1E235/image-dimensions/460x341?v=v2 "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](https://community.atlassian.com/t5/Jira-Service-Management/Jira-API-Insight-object-customfield/qaq-p/1276723), it looks like [@djenkins](/t5/user/viewprofilepage/user-id/924221) 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](https://community.atlassian.com/t5/image/serverpage/image-id/126783iF6D6D37A0784064E/image-dimensions/454x463?v=v2 "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_](/t5/user/viewprofilepage/user-id/853596) 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. :-}

comments: author: Darryl Lee
body: 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.


author: Ravi Sagar _Sparxsys_
body: That is a wonderful idea. Let me try using ScriptRunner to do this more efficiently. ?


author: Stephen Letch
body: Hi [@Ravi Sagar _Sparxsys_](/t5/user/viewprofilepage/user-id/853596)

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](/t5/user/viewprofilepage/user-id/1365322) 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


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


author: Steve Letch
body: 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. :(


author: Ravi Sagar _Sparxsys_
body: Hi [@Stephen Letch](/t5/user/viewprofilepage/user-id/4038567)

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


Tags: cloud

server