<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
.form-section {
margin-bottom: 15px;
}
.form-control{
border-color: #939593;
}
</style>
<g:ui_form>
<input type="hidden" id="secId" name="secId" value="${JS,HTML:sysparm_sys_id}"/>
<input type="hidden" id="action" name="action" value="${JS,HTML:sysparm_action}"/>
<input id="react" name="react" type="hidden" value="${JS,HTML:sysparm_react}" />
<input id="resource_url" name="resource_url" type="hidden" value="${JS,HTML:sysparm_resource}" />
<g:evaluate jelly="true">
var jvar_secIncId = jelly.sysparm_sys_id;
var secInc = new GlideRecord("sn_si_incident");
var exist = secInc.get(jvar_secIncId);
if (!exist)
secInc.newRecord();
secInc;
</g:evaluate>
<div class="modal-body">
<div class="row form-section">
<label for="ci" class="col-sm-3 section-title-top">${gs.getMessage('Configuration item')}</label>
<div class="col-sm-5 section-title-top">
<input readonly="true" id="ci" class="col-sm-9 form-control" type="text" name="ci" value="$[JS,HTML:secInc.getDisplayValue('cmdb_ci')]" aria-label="${JS,HTML:gs.getMessage('Configuration item')}"></input>
</div>
</div>
<div class="row form-section">
<label class="col-sm-3 section-title-top">${gs.getMessage('Location')}</label>
<div class="col-sm-5 section-title-top">
<input readonly="true" id="loc" class="col-sm-9 form-control" type="text" name="loc" value="$[JS,HTML:secInc.getDisplayValue('location')]" aria-label="${JS,HTML:gs.getMessage('Location')}"></input>
</div>
</div>
<j:if test="${sysparm_action != 'change_request'}">
<div class="row form-section">
<div class="col-sm-3 section-title-top">${gs.getMessage('Impact')}</div>
<div class="col-sm-3">
<g:evaluate var="jvar_property">
var prop;
if ("${sysparm_action}" == "incident")
prop = GlideChoiceList.getChoiceList('incident', 'impact');
else if ("${sysparm_action}" == "problem")
prop = GlideChoiceList.getChoiceList('problem', 'impact');
</g:evaluate>
<select id="impact" class="form-control" name="impact" value="$[JS,HTML:secInc.impact]">
<g2:options choiceList="$[prop]" choiceValue="$[secInc.impact.toString()]" />
</select>
</div>
</div>
<div class="row form-section">
<div class="col-sm-3 section-title-top">${gs.getMessage('Urgency')}</div>
<div class="col-sm-3">
<g:evaluate var="jvar_property">
var prop1;
if ("${sysparm_action}" == "incident")
prop1 = GlideChoiceList.getChoiceList('incident', 'urgency');
else if ("${sysparm_action}" == "problem")
prop1 = GlideChoiceList.getChoiceList('problem', 'urgency');
</g:evaluate>
<select id="urgency" class="form-control" name="urgency" value="$[JS,HTML:secInc.urgency]">
<g2:options choiceList="$[prop1]" choiceValue="$[secInc.urgency.toString()]" />
</select>
</div>
</div>
<!--Issue field on incident form-->
<div class="row form-section">
<div class="col-sm-3 section-title-top">${gs.getMessage('Issue with')}</div>
<div class="col-sm-3">
<g:evaluate var="jvar_property">
var prop2;
if ("${sysparm_action}" == "incident")
prop2 = GlideChoiceList.getChoiceList('incident', 'u_choice_issue');
else if ("${sysparm_action}" == "problem")
prop2 = GlideChoiceList.getChoiceList('problem', 'u_choice_issue');
</g:evaluate>
<select id="u_choice_issue" class="form-control" name="u_choice_issue" value="$[JS,HTML:secInc.u_choice_issue]">
<g2:options choiceList="$[prop2]" choiceValue="$[secInc.u_choice_issue.toString()]" />
</select>
</div>
</div>
</j:if>
<j:if test="${sysparm_action == 'change_request'}">
<div class="row form-section">
<div class="col-sm-3 section-title-top">${gs.getMessage('Priority')}</div>
<div class="col-sm-3">
<g:evaluate var="jvar_property">
var prList = GlideChoiceList.getChoiceList('change_request', 'priority');
</g:evaluate>
<select id="priority" class="form-control" name="priority" aria-label="priority">
<g2:options choiceList="$[prList]" choiceValue="$[secInc.priority.toString()]" />
</select>
</div>
</div>
</j:if>
<div class="row form-section">
<label for="short_desc" class="col-sm-3 section-title-top">${gs.getMessage('Short description')}</label>
<div class="col-sm-9 section-title-top">
<input id="short_desc" class="col-sm-9 form-control" type="text" name="short_desc" value="$[JS,HTML:secInc.short_description]" aria-label="${JS,HTML:gs.getMessage('Short description')}"></input>
</div>
</div>
<div class="row form-section">
<label for="desc" class="col-sm-3 section-title-top">${gs.getMessage('Description')}</label>
<span class="col-sm-9 section-title-top">
<textarea id="desc" class="col-sm-9 form-control" rows="3" name="desc" aria-label="${JS,HTML:gs.getMessage('Description')}">${HTML:secInc.description}</textarea>
</span>
</div>
</div>
<footer class="modal-footer">
<!-- <g:dialog_buttons_ok_cancel ok="return onSubmit();" cancel="return onCancel();"/> -->
<button class="btn-default btn" style="min-width: 5em" onclick="return onCancel();" name="cancel" id="cancel">${gs.getMessage('Cancel')}</button>
<button class="btn-primary btn" onclick="return onSubmit();" name="submit" id="submit" style="min-width: 5em">${gs.getMessage('Submit')}</button>
</footer>
</g:ui_form>
</j:jelly>
Client Script
function setCustomEvent() {
if (typeof window.CustomEvent === "function") return false; //If not IE
function CustomEvent(event, params) {
params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
}
function onCancel() {
if (gel('react').value) {
var event;
//The following if-else is 'Event' polyfill for IE
if (typeof(Event) === 'function') {
event = new Event('SIR_WORKBENCH_POPUP_CANCEL');
} else {
event = document.createEvent('Event');
event.initEvent('SIR_WORKBENCH_POPUP_CANCEL', true, true);
}
window.parent.dispatchEvent(event);
} else
GlideDialogWindow.get().destroy();
return false;
}
function onSubmit() {
window.setTimeout(function() {
jQuery("#submit").prop('disabled', true);
});
var result = true;
if (gel('react').value) {
try {
var body = {};
if(gel('secId'))
body['si_sys_id']= gel('secId').value;
if(gel('short_desc'))
body['short_desc']= gel('short_desc').value;
if(gel('desc'))
body['description']= gel('desc').value;
if(gel('impact'))
body['impact']= gel('impact').value;
if(gel('urgency'))
body['urgency']= gel('urgency').value;
if(gel('ci'))
body['cmdb_ci']= gel('ci').value;
if(gel('loc'))
body['location']= gel('loc').value;
if(gel('priority'))
body['priority']= gel('priority').value;
// for Issue with field
if(gel('u_choice_issue'))
body['u_choice_issue']= gel('u_choice_issue').value;
var restEndPoint = "/api/sn_app_secops_ui/v1/secops_ui_si_actions/" + gel('resource_url').value;
var requestBody = JSON.stringify(body);
var client = new XMLHttpRequest();
client.open("post", restEndPoint);
client.setRequestHeader('Accept', 'application/json');
client.setRequestHeader('Content-Type', 'application/json');
client.setRequestHeader("X-UserToken", g_ck);
client.setRequestHeader("X-WantSessionNotificationMessages", true);
client.onreadystatechange = function() {
if (this.readyState == this.DONE) {
setCustomEvent();
params = {
detail: JSON.parse(this.response)
};
window.parent.dispatchEvent(new CustomEvent('SIR_WORKBENCH_POPUP_SUBMIT', params));
//console.log(JSON.parse(this.response));
}
};
client.send(requestBody);
return false;
} catch (e) {
return true;
}
}
return true;
}
Processing Script
var securityIncident = new GlideRecord("sn_si_incident");
if (/^[0-9a-fA-F]{32}$/.test(secId))
securityIncident.get(secId);
else
secId = securityIncident.getUniqueIdentifier();
securityIncident.description = desc;
securityIncident.short_description = short_desc;
if (action == "change_request") {
securityIncident.priority = priority;
var changeRequest = (new SecurityIncidentUtils1()).createChangeFromSecurityIncident(securityIncident);
if(changeRequest.indexOf("Error") == -1)
gs.addInfoMessage(gs.getMessage("Change request {0} was created.", changeRequest));
else
gs.addErrorMessage(gs.getMessage("Could not create the Change Request."));
}
else if (action == "incident") {
securityIncident.impact = impact;
securityIncident.urgency = urgency;
// Need urgency and impact together to generate Incident priority
var incident = (new SecurityIncidentUtils1()).createIncidentFromSecurityIncident1(securityIncident);
if(incident.indexOf("Error") == -1)
gs.addInfoMessage(gs.getMessage("Incident {0} was created.", incident));
else
gs.addErrorMessage(gs.getMessage("Could not create the Incident."));
}
else if (action == "problem") {
securityIncident.impact = impact;
securityIncident.urgency = urgency;
var prb = (new SecurityIncidentUtils1()).createProblemFromSecurityIncident(securityIncident);
if (prb.indexOf("Error") == -1)
gs.addInfoMessage(gs.getMessage("Problem {0} was created.", prb));
else
gs.addErrorMessage(gs.getMessage("Could not create the Problem."));
}
response.sendRedirect("sn_si_incident.do?sysparm_query=sys_id=" + secId);