Need help with UI action script

Harikrishna4
Tera Contributor

Hello Everyone,

I have a requirement to create incident from selected list of alerts from alerts table 

I have created UI action script 

function open_incident() {
    var selsysIDs = g_list.getChecked();
    var selectedAlerts = selsysIDs.split(',');

    for (var i = 0; i < selectedAlerts.length; i++) {
        var alertSysId = selectedAlerts[i];

        // Query the alert record
        var gr = new GlideRecord('em_alert');
        gr.addQuery('sys_id', alertSysId);
        gr.query();

        if (gr.next()) {
            // Create an incident record
            var incident = new GlideRecord('incident');
            incident.initialize();
            incident.u_source = 'alarm';
        
            incident.short_description = 'Incident created from alert ' + ' ' + gr.number;
            incident.description = gr.description;
           incident.insert();
            gs.info('Incident created successfully from selected alert: ' + alertSysId);
        }
            // Link the alert to the incident
            gr.setValue('incident',incident.sys_id);
            gr.update();
       
    }
    g_list.refresh();
    gs.info('Created Incident' + incident.number);
}
Incidents are getting created but
When I'm clicking on the action button, I'm getting scope error and unable to tag those incidents with the alerts
Please let me know if I missed anything.
Harikrishna4_0-1699609148301.png

 

 
Thanks,
Hari
1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

This is happening because your tables/records are in different applications and the default behavior of the system is to prevent the access to your scoped tables from outside their scope.

What you need to do is to define cross-scope priviledges, as described in the docs.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

3 REPLIES 3

Martin Ivanov
Giga Sage
Giga Sage

This is happening because your tables/records are in different applications and the default behavior of the system is to prevent the access to your scoped tables from outside their scope.

What you need to do is to define cross-scope priviledges, as described in the docs.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

@Harikrishna4 Did my answer help you resolve your issue? Do not forget to mark it as Correct.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Hi Martin,

 

Thanks for giving me the clarification.

 

Regards,

Hari