Loading "Propose Major Incident" modal if major incident trigger == true

James T
Tera Contributor

I have set up the Major Incident Module to trigger an automatic proposal of a Major Incident Candidate if Prioirity == 1 or 2. The automatic trigger currently allows a user to raise priority and trigger the candidate without providing the necessary Impact statemetn etc that would normally be completed if you proposed using the "Propose Major Incident" UI.

As such I'd like to trigger the modal called in the Propose Major Incident UI if the Prioirty == 1 or 2. If the user hits cancel it reverts the priority to the orignal priority <2.  Below is the script called from the Propose Major Incident UI:

 

function promptForProposalReason() {
	//checking for work_notes visibility
	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);
}
1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

If my understanding of what you are trying to achieve is correct, all you need to do is create an onChange client script for Priority field on Incident table and re-use the code from the OOB "Propose Major Incident" UI Action there. This way you will get the dialog window opened when Priority changes on the Incident form.

Of course, you will need to add appropriate conditions to your client script to only trigger it when newValue equals 1 or 2.

The rest will be taken care of by the OOB functionality of the dialog window (i.e. "mim_propose" UI page). If you press Propose, it will save the incident (including the Priority selected by the user). If you press Cancel, it will close the dialog window without saving the incident or navigating away.

If you want to reset Priority to its initial value, you need to store it somewhere in advance. I would recommend using the g_scratchpad object and a Display Business Rule for that. To set that value upon closure of the dialog window, add a call to g_form.setValue method to the close() function defined in the Client Script part of the "mim_propose" UI Page.

NB: If Priority is not set directly but rather calculated from the values of other fields (e.g., Impact and Urgency), you will need to manipulate the values of those fields instead.

Optionally, you may want to deactivate the OOB "Propose Major Incident" UI action.

View solution in original post

1 REPLY 1

Slava Savitsky
Giga Sage

If my understanding of what you are trying to achieve is correct, all you need to do is create an onChange client script for Priority field on Incident table and re-use the code from the OOB "Propose Major Incident" UI Action there. This way you will get the dialog window opened when Priority changes on the Incident form.

Of course, you will need to add appropriate conditions to your client script to only trigger it when newValue equals 1 or 2.

The rest will be taken care of by the OOB functionality of the dialog window (i.e. "mim_propose" UI page). If you press Propose, it will save the incident (including the Priority selected by the user). If you press Cancel, it will close the dialog window without saving the incident or navigating away.

If you want to reset Priority to its initial value, you need to store it somewhere in advance. I would recommend using the g_scratchpad object and a Display Business Rule for that. To set that value upon closure of the dialog window, add a call to g_form.setValue method to the close() function defined in the Client Script part of the "mim_propose" UI Page.

NB: If Priority is not set directly but rather calculated from the values of other fields (e.g., Impact and Urgency), you will need to manipulate the values of those fields instead.

Optionally, you may want to deactivate the OOB "Propose Major Incident" UI action.