Skip to content

Commit 4b65819

Browse files
authored
Major incident proposal (#1143)
1 parent 25b447e commit 4b65819

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function onSubmit() {
2+
var priority = g_form.getValue('priority');
3+
4+
if (priority == '1') {
5+
// is already a Major Incident
6+
var gaCheck = new GlideAjax('CreateMajorIncident');
7+
gaCheck.addParam('sysparm_name', 'isAlreadyMajorIncident');
8+
gaCheck.addParam('sysparm_sysid', g_form.getUniqueValue());
9+
10+
var response = gaCheck.getXMLWait();
11+
var isMajorIncident = response.documentElement.getAttribute('answer');
12+
13+
// not yet a Major Incident
14+
if (isMajorIncident == 'false') {
15+
var resp = confirm(getMessage('Please confirm that you would like to propose a Major Incident Candidate?'));
16+
17+
if (resp) {
18+
// propose the Major Incident
19+
var ga = new GlideAjax('CreateMajorIncident');
20+
ga.addParam('sysparm_name', 'majorIncCreate');
21+
ga.addParam('sysparm_sysid', g_form.getUniqueValue());
22+
23+
var majorIncidentResponse = ga.getXMLWait();
24+
var incidentNumber = majorIncidentResponse.documentElement.getAttribute('answer');
25+
26+
alert("Incident " + incidentNumber + " has been proposed as a Major Incident candidate.");
27+
} else {
28+
// cancels
29+
return false;
30+
}
31+
}
32+
}
33+
34+
return true; // Allow if priority is not 1 or after processing
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var CreateMajorIncident = Class.create();
2+
CreateMajorIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
majorIncCreate: function() {
5+
6+
var incSysId = this.getParameter('sysparm_sysid');
7+
8+
var ginc = new GlideRecord('incident');
9+
10+
if (ginc.get(incSysId)) {
11+
12+
ginc.major_incident_state = 'proposed';
13+
ginc.proposed_by = gs.getUserID();
14+
ginc.proposed_on = new GlideDateTime();
15+
ginc.work_notes = "Hello World! " + new GlideDateTime();
16+
ginc.update();
17+
18+
return ginc.number.toString();
19+
}
20+
21+
return 'false';
22+
},
23+
24+
25+
isAlreadyMajorIncident: function() {
26+
var incSysId = this.getParameter('sysparm_sysid');
27+
var ginc = new GlideRecord('incident');
28+
29+
if (ginc.get(incSysId)) {
30+
return ginc.major_incident_state == 'proposed' ? 'true' : 'false';
31+
}
32+
33+
return 'false';
34+
},
35+
36+
type: 'CreateMajorIncident'
37+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<h1>Major Incident Proposal - Client Script & Script Include</h1>
2+
3+
<p>This solution asks the users to propose an incident as a <strong>Major Incident</strong> candidate. The process is initiated from the <strong>Incident</strong> form when the priority is set to <strong>1 (Critical)</strong>, and the system checks if the incident has already been proposed as a Major Incident. If not, the user is prompted to confirm whether they wish to propose the incident. Upon confirmation, the incident is updated, and the <strong>Major Incident</strong> status is assigned.</p>
4+
5+
<p>This solution consists of a <strong>Client Script</strong> and a <strong>Script Include</strong>, which handle the user interaction and the back-end logic, respectively.</p>
6+
7+
<h2>Functionality</h2>
8+
9+
<h3>1. Client Script - <code>onSubmit()</code></h3>
10+
<p>The <strong>Client Script</strong> is triggered when the user submits an Incident form with a priority of <strong>1 (Critical)</strong>. It performs the following actions:</p>
11+
<ul>
12+
<li>Checks if the incident is already marked as a Major Incident by calling the Script Include via <strong>GlideAjax</strong>.</li>
13+
<li>If the incident is not already marked as a Major Incident, the user is prompted to confirm whether they wish to propose it as a Major Incident.</li>
14+
<li>Upon confirmation, the incident is proposed as a Major Incident candidate, and a success message is displayed with the incident number.</li>
15+
</ul>
16+
17+
<h4>Key Features:</h4>
18+
<ul>
19+
<li><strong>Priority Check</strong>: The script only runs when the priority is set to 1 (Critical).</li>
20+
<li><strong>GlideAjax Call</strong>: Uses <strong>GlideAjax</strong> to communicate with the server-side <strong>Script Include</strong> to check and propose the Major Incident.</li>
21+
<li><strong>User Confirmation</strong>: The user is prompted to confirm the proposal of the Major Incident before proceeding.</li>
22+
<li><strong>Synchronous Execution</strong>: The script waits for a response from the server using <code>getXMLWait()</code> to ensure the process completes before submitting the form.</li>
23+
</ul>
24+
25+
26+
27+
<h3>2. Script Include - <code>CreateMajorIncident</code></h3>
28+
<p>The <strong>Script Include</strong> provides the back-end logic for:</p>
29+
<ul>
30+
<li>Checking whether the incident is already proposed as a Major Incident.</li>
31+
<li>Proposing the incident as a Major Incident by updating its <code>major_incident_state</code>, <code>proposed_by</code>, and <code>proposed_on</code> fields, and adding work notes.</li>
32+
</ul>
33+
34+
35+
36+
<h3>Usage Example:</h3>
37+
<ol>
38+
<li>When the priority of an incident is set to <strong>1 (Critical)</strong>, the client script checks whether the incident is already a Major Incident.</li>
39+
<li>If not, the user is prompted to confirm the Major Incident proposal.</li>
40+
<li>Upon confirmation, the <code>CreateMajorIncident</code> Script Include updates the incident record to reflect its <strong>proposed</strong> Major Incident status and returns the incident number.</li>
41+
</ol>
42+
43+
<h2>Customization</h2>
44+
<p>You can easily customize this functionality by:</p>
45+
<ul>
46+
<li>Adding more validation rules to the Script Include.</li>
47+
<li>Modifying the client script to handle different priorities or additional fields.</li>
48+
<li>Updating the work notes or other fields when proposing the incident.</li>
49+
</ul>

0 commit comments

Comments
 (0)