Itsm

Snowl13052025
Tera Contributor

I want a popup on the incident form if I try to resolve the incident while the associated alert is still open and help me the script and solution.

 

thanks in advance 

1 ACCEPTED SOLUTION

Bhimashankar H
Mega Sage

Hi @Snowl13052025 ,

 

I hope you saw my reply.

----------------------------------------------------------------------------------------
If my answer helps you or resolves your query, please consider marking as 'Accept As Solution'. So future readers with similar questions can find it easily. Your coordination will help community to grow stronger!.
----------------------------------------------------------------------------------------

Thank you.
Bhimashankar

View solution in original post

11 REPLIES 11

Thanks for the quick reply @Shraddha Kadam 

Shraddha, this is actually related to Event Management. We have an alert table (em_alert) from which incidents are created. However, incidents are getting closed even when the associated alerts are still in the open state. To prevent this, I want a popup message to appear when someone tries to close the incident while the alert is still open.

 

You can use Before update business rule. Using gs.addErrorMessage() you can show up popup message on the Incident form

If my response was helpful, please mark it as correct and helpful.
Thank you.

Hi @Snowl13052025 ,

 

You can do this by writing before business rule or client script.

1. Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return; 
    }

    // Check if the new state is "Resolved" (value 6 in default Incident state model)
    if (newValue == '6') { 
        var incidentSysId = g_form.getUniqueValue(); 
        var ga = new GlideAjax('CheckOpenAlerts');  //You need to call the glideajax to query on 'em_alert' table
        ga.addParam('sysparm_name', 'checkForOpenAlerts'); 
        ga.addParam('sysparm_incident_id', incidentSysId); 

        ga.getXMLAnswer(function(response) {
            var result = JSON.parse(response);
            if (result.hasOpenAlert) {
                // Show pop-up and revert state to previous value
                g_form.addErrorMessage('Please close the alert for this incident first');
                g_form.setValue('state', oldValue); // Revert to previous state
            }
        });
    }
}

 

GlideAjax class

var CheckOpenAlerts = Class.create();
CheckOpenAlerts.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkForOpenAlerts: function() {
        var incidentId = this.getParameter('sysparm_incident_id');
        var alertGr = new GlideRecord('em_alert');
        alertGr.addQuery('incident', incidentId); // Assumes 'incident' field links to incident table
        alertGr.addQuery('state', 'Open'); // Adjust 'Open' to match your em_alert state value
        alertGr.query();

        if (alertGr.hasNext()) {
            return JSON.stringify({ hasOpenAlert: true });
        }
        return JSON.stringify({ hasOpenAlert: false });
    },

    type: 'CheckOpenAlerts'
});

Here I am assuming that in 'em_alert' table is associated with incident table and there inc filed defines the relation between these 2 tables.

 

This way you can show alert message.

 

2. Before business rule

(function executeRule(current, previous /*null when async*/) {
    var alertGr = new GlideRecord('em_alert');
    alertGr.addQuery('incident', current.sys_id);
    alertGr.addQuery('state', 'Open'); //Adjust to correct value in state of alert
    alertGr.query();
    
    if (alertGr.hasNext()) {
        gs.addErrorMessage('Please close the alert for this incident first');
        current.setAbortAction(true); // Prevent the state change
    }
})(current, previous);

So it will update the incident state if it has any open alerts and shows the error.

 

Thanks,

Bhimashankar

 

----------------------------------------------------------------------------------------
If my answer helps you or resolves your query, please consider marking as Helpful/ 'Accept As Solution'. So future readers with similar questions can find it easily. Your coordination will help community to grow stronger!.
----------------------------------------------------------------------------------------

May I know Will this work on  the csm configurable workspace as well ?

Yes it should work, as far as the relation between table is correct and here if you use the glideAjax you can customize the class as you require.

 

Regards,

Bhimashankar


-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful'. Thanks!