Need help with the UI action script

Harikrishna4
Tera Contributor
I have written the below code to create incidents from the alert list view, It's creating Incidents but for some reason it's unable to execute the bold condition.
Please find the script
 
function create_incident(){
 var selsysIDs = g_list.getChecked();
 var selectedAlerts = selsysIDs.split(',');
 if (selectedAlerts.length >= 1) {
     var incident = new GlideRecord('incident');
     incident.initialize();
     incident.u_source = 'alarm';
     incident.u_source_type = 'bpuaa';
     incident.short_description = 'Incident created from alert ';
     incident.description = 'Created from Alert';
     var inc = incident.insert();
     for (var i = 0; i < selectedAlerts.length; i++) {
         var id = selectedAlerts[i];
         var gr = new GlideRecord('em_alert');
         if (!gr.get(id))
             continue;
         gr.setValue('incident', inc);
         gr.update();
         g_list.refresh();
     }
     gs.addInfoMessage('Incident' + inc.number + 'created');
 }
}
 
Can someone help me with this ui action
Thanks,
hari
1 REPLY 1

Amit Gujarathi
Giga Sage
Giga Sage

HI @Harikrishna4 ,
I trust you are doing great.
Please find the updated code:

function create_incident() {
    var selsysIDs = g_list.getChecked();
    var selectedAlerts = selsysIDs.split(',');
    if (selectedAlerts.length >= 1) {
        var incidentNumber; // Variable to store the incident number
        var incident = new GlideRecord('incident');
        incident.initialize();
        incident.u_source = 'alarm';
        incident.u_source_type = 'bpuaa';
        incident.short_description = 'Incident created from alert';
        incident.description = 'Created from Alert';
        var incSysId = incident.insert(); // Insert the incident and get its sys_id

        if (incSysId) {
            incident.get(incSysId); // Retrieve the incident to get its number
            incidentNumber = incident.number;

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

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi