Retrieve asset key from InsightObjectUpdatedEvent

I am trying to use listeners to avoid using the asset automations in Jira service management. I need to update attributes when certain other attributes are updated. I am having a problem get the asset key from the event and have been unable to find exactly how to do that. I found the info for issues (HERE) but not assets.

I am new to groovy and have been trying to stick to using HAPI as much as possible since the regular groovy scripts are still a little beyond me…for now. Any help or guidance would be greatly appreciated.

Hi NWHSbspangler,
Jira Listener are Event based. This mean in listener context there will be an even or issue object. Those can be used in your script. But as far you mentioned Jira ServiceManagement you probably need “Insight automation rules”. See more info here: Configuring Insight automation rules | Jira Service Management Data Center 4.21 | Atlassian Documentation
This mean unfortunately you won;t be able to use HAPI direcly. But there are two options to proceed from there: HTTP request or server based Groovy script.
You can call HAPI script as ScriptRunner REST API endpoint from there.

Since the InsightObjectUpdated event is listed in the in the listener triggers I was hoping to use it here. All I am trying to do is update one object attribute if another is changed. But As far as I can tell there is no event.object or similar object like there is with issues. I know I can use the insight automation rules but that context is almost unusable in my experience. I was hoping for some documentation on the Listener Insight triggers as I have been unable to find anything usable. If I am stuck with the Insight automation rules could you point me to some documentation or an example of how to call a HAPI scipt as a scriptrunner REST API endpoint? It would be greatly appreciated. thank you

Hi Bryan,
Indeed, I’ve found this event in dropdown box of CustomEvent creation form. But when I try to add listener for event “InsightObjectUpdatedEvent” it fails with error:

startup failed: General error during canonicalization: java.lang.NoClassDefFoundError: com.riadalabs.jira.plugins.insight.services.events.InsightAsyncEvent

Anyway, as far as it is not possible to find any documentation on this Event, I would consider it as private one and would not use it in production.

Regarding task “process updates on insight records with HAPI”, try the following.

  1. create ScriptRunner REST endpoint
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

event_update_asset_rec(httpMethod: "GET", groups: ["grp-jira-admin", "grp-robots-jira"]) { MultivaluedMap queryParams, String body ->
    if (queryParams.containsKey("id")){
        String rec_id = queryParams.getFirst("id")
        if(!rec_id.isEmpty()){
          log.warn("rec_id:${rec_id} ${rec_id.getClass()}")
          Assets.getById(rec_id?.toInteger()).each { rec ->
              log.warn("processing ${rec} ${rec.getClass()}")
          }
        }
    }
    return Response.ok().header("Content-Type", "application/json").entity([msg: "done"]).build()
}

  1. create Insight Automation for even ObjectUpdated.
    When: ObjectUpdated, IF: anyObject, THEN: HTTP
    in HTTP config set URL with parameter:
    https://yourjirainstance/rest/scriptrunner/latest/custom/event_update_asset_rec?id=${objectId}

this should do the signaling on Insight object update to your endpoint “event_update_asset_rec”

Hope this helps.