Alert creation

I_Das
Tera Contributor

Hello All,

I want to create an alert when an user is trying to raise an incident based on a configuration item which is having an current outage. So I write a client script and script include. But the alert is still not showing.

 

Client script:-

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var configItem = g_form.getValue('cmdb_ci');
  var hasOutage = new GlideAjax('CheckOutageScriptInclude').getXMLWait(configItem);
   if(hasOutage == 'true')
   {
    alert('This CI has outage');
    return false;
   }
   return true;
 
 
Script include:-
var CheckOutageScriptInclude = Class.create();
CheckOutageScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getXML: function()
{
    var configItem = this.getParameter('sysparm_cmdb_ci');
    var hasOutage = this._checkForOutage(configItem);
    return hasOutage.toString();
},
_checkForOutage: function(configItem)
{
    var outageGr = new GlideRecord('cmdb_ci_outage');
    outageGr.addQuery('cmdb_ci', configItem);
    outageGr.addQuery('end', '>' , new GlideDateTime());
    outageGr.query();
if(outageGr.next())
    {
return true;
    }
   return false;
}
    //type: 'CheckOutageScriptInclude'
});
 
}
 
Could you please tell what is the problem? Or how to do it?
1 ACCEPTED SOLUTION

Arun_Manoj
Mega Sage

Hi @I_Das ,

 
function onSubmit() { var configItem = g_form.getValue('cmdb_ci'); // Make a GlideAjax call to check if the CI has an outage
var ga = new GlideAjax('CheckOutageScriptInclude');
ga.addParam('sysparm_name', 'getXML');
ga.addParam('sysparm_cmdb_ci', configItem);
ga.getXMLAnswer(function(response) { if (response == 'true') {
alert('This CI has an outage. Incident cannot be raised.');
g_form.clearMessages(); // Clear any previous messages
return false; // Prevent form submission
} else
{
return true; // Allow form submission
} }); // Ensure the form submission is halted until the response is received
return false;
}
 
script include:

 

 
var CheckOutageScriptInclude = Class.create();
CheckOutageScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getXML: function() {
var configItem = this.getParameter('sysparm_cmdb_ci');
var hasOutage = this._checkForOutage(configItem);
return hasOutage.toString();
}, _checkForOutage: function(configItem) {
var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.addQuery('cmdb_ci', configItem);
outageGr.addQuery('end', '>', new GlideDateTime());
outageGr.query(); return outageGr.hasNext();
} });
 
please mark it as helpfuls, if the solution is fine.
 
Thanks
Arun

 

View solution in original post

4 REPLIES 4

Arun_Manoj
Mega Sage

Hi @I_Das ,

 
function onSubmit() { var configItem = g_form.getValue('cmdb_ci'); // Make a GlideAjax call to check if the CI has an outage
var ga = new GlideAjax('CheckOutageScriptInclude');
ga.addParam('sysparm_name', 'getXML');
ga.addParam('sysparm_cmdb_ci', configItem);
ga.getXMLAnswer(function(response) { if (response == 'true') {
alert('This CI has an outage. Incident cannot be raised.');
g_form.clearMessages(); // Clear any previous messages
return false; // Prevent form submission
} else
{
return true; // Allow form submission
} }); // Ensure the form submission is halted until the response is received
return false;
}
 
script include:

 

 
var CheckOutageScriptInclude = Class.create();
CheckOutageScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getXML: function() {
var configItem = this.getParameter('sysparm_cmdb_ci');
var hasOutage = this._checkForOutage(configItem);
return hasOutage.toString();
}, _checkForOutage: function(configItem) {
var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.addQuery('cmdb_ci', configItem);
outageGr.addQuery('end', '>', new GlideDateTime());
outageGr.query(); return outageGr.hasNext();
} });
 
please mark it as helpfuls, if the solution is fine.
 
Thanks
Arun

 

I_Das
Tera Contributor

Hello @Arun_Manoj ,

It worked. Thank you.

Samiksha Gunjat
Kilo Guru

Hi  @I_Das,

 

Client Script:-

function onSubmit() {
var configItem = g_form.getValue('cmdb_ci');
var hasOutage = new GlideAjax('CheckOutageScriptInclude').getXMLWait(configItem);
if (hasOutage == 'true') {
alert('This CI has an outage.');
return false; // Prevent form submission
}
return true; // Allow form submission
}

 

Script Include:-

var CheckOutageScriptInclude = Class.create();
CheckOutageScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getXMLWait: function(configItem) {
var hasOutage = this._checkForOutage(configItem);
return hasOutage.toString();
},

_checkForOutage: function(configItem) {
var outageGr = new GlideRecord('cmdb_ci_outage');
outageGr.addQuery('cmdb_ci', configItem);
outageGr.addQuery('end', '>', new GlideDateTime());
outageGr.query();
if (outageGr.next()) {
return true;
}
return false;
}
});

 

Please mark this comment as if it helped you. 

Regards,

Samiksha Gunjate

 
 
 
 
 

I_Das
Tera Contributor

Hello @Arun_Manoj ,

But before I also created a business rule on incident table where if one P1 incident will be raised an outage will automatically create. Though this is working to create alert that business rule is not triggering. How can I solve that issue?

My actual requirement was when a major incident will be raised an outage will be created automatically. Now if another user tries to raise incident based on the same configuration item which has outage ongoing it will create alert on portal.