Propose a Major incident UI action for P1/P2

Priyadharshini6
Tera Expert

Hi

 

I have a required to show the "Propose a major incident" UI action on all priorities ( P1-P4) , but once user clicks the UI action, it should allow them to propose only if the current priority is P1/P2, for P3/P4 there should be a pop-up informing them , that they can't

 

- I was able to achieve the visibility part with the below UI Action condition. 

  " current.priority == 1 || current.priority == 2 || current.priority == 3 || current.priority == 4"

 

- But i am stuck with the UI action script part, the changes doesn't seem to work, Can someone suggest, what went wrong in the script part

 

----------------------------------------------------------------------------------------------

function promptForProposalReason() {

//Checking for P3/P4 <Custom code part>
if((current.priority == 3 )|| (current.priorty ==4))
{
g_form.addErrorMessage("Propose major incident is not allowed for P3/P4");
current.setAbortAction(true);
}

//Checking for worknotes
if(!g_form.getControl('work_notes')) {
getMessage('Cannot propose major incident as "Worknotes" is not visible', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
var dialog = new GlideModal('sn_major_inc_mgmt_mim_propose', false, 651, 250);
getMessage('Propose Major Incident', function(msg) {
dialog.setTitle(msg);
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
dialog.template = glideModalTemplate;
dialog.on('bodyrendered', function(event) {
glideModalKeyDownHandler(event, dialog.getID());
});
dialog.setPreference('WORK_NOTES', g_form.getValue('work_notes'));
dialog.setPreference('BUSINESS_IMPACT', g_form.getValue('business_impact'));
dialog.setPreference("focusTrap", true);
dialog.render();
});
//This dialog will be destroyed in UI Page 'sn_major_inc_mgmt_mim_propose'
}


if(typeof window == 'undefined')
proposeMICOnConfirmation();

//Server-side code
function proposeMICOnConfirmation() {
current.major_incident_state = new sn_major_inc_mgmt.MajorIncidentTriggerRules().MAJOR_INCIDENT_STATE.PROPOSED;
current.update();
gs.addInfoMessage(gs.getMessage('{0} has been proposed as a major incident candidate', current.getDisplayValue()));
action.setRedirectURL(current);
}

 

-------------------------------------------------------------------------------------------------------------------------------

 

2 REPLIES 2

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Priyadharshini6 

replace below line of code :-

g_form.addErrorMessage("Propose major incident is not allowed for P3/P4");

With :-

gs.addErrorMessage("Propose major incident is not allowed for P3/P4");

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Thanks for your suggestion. It wasn't still working.

 

Meantime, i found the issue, was basically executing current object at the wrong place. The below code works.

 

============================================================================

function promptForProposalReason() {
//checking for work_notes visibility

var prior = g_form.getValue('priority');


if((prior == 3) || (prior ==4))

{
alert("Major Incident can't be proposed for P3/P4");
return false;

}



if(!g_form.getControl('work_notes')) {
getMessage('Cannot propose major incident as "Worknotes" is not visible', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
var dialog = new GlideModal('sn_major_inc_mgmt_mim_propose', false, 651, 250);
getMessage('Propose Major Incident', function(msg) {
dialog.setTitle(msg);
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
dialog.template = glideModalTemplate;
dialog.on('bodyrendered', function(event) {
glideModalKeyDownHandler(event, dialog.getID());
});
dialog.setPreference('WORK_NOTES', g_form.getValue('work_notes'));
dialog.setPreference('BUSINESS_IMPACT', g_form.getValue('business_impact'));
dialog.setPreference("focusTrap", true);
dialog.render();
});
//This dialog will be destroyed in UI Page 'sn_major_inc_mgmt_mim_propose'
}

========================================================================