- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 09:24 AM
Hi All,
I am having a very frustrating problem occur. We have been asked to add a popup box when the "Create Incident" button is selected in the Service Operations Workspace for the interaction form. This popup box should allow for the Incident's Impact, Urgency, and Assignment group to be set before clicking OK and having the incident be generated with those parameters.
I have been able to successfully generate the popup using g_modal, and this is not the problem.
The problem is the actual generating of the incident. I am able to generate the incident without issue as long as I don't set the impact and urgency via the script include, however this is not what is desired as it will generate extra steps for our Service Desk. Adding the impact and urgency to the script include causes it to, more often then not, freeze and not return any results, but the incident does get created. Below are my scripts for my UI Action and my Script Include as I am at a loss of what could possibly be the problem.
UI Action:
function onClick(g_form) {
//get Impact and urgency choices
var impactChoices = getChoices('impact', 'task');
var urgencyChoices = getChoices('urgency', 'task');
//If the CI has an ownership group pre-populate the assignment group field in the popup.
var answer;
var ga = new GlideAjax('createIncident');
ga.addParam('sysparm_name', 'autoAssign');
ga.addParam('sysparm_sysID', g_form.getValue('u_cmdb_ci'));
ga.getXML(callBackFunction);
function callBackFunction(response) {
answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
//Display popup box.
g_modal.showFields({
title: "Enter the Impact, Urgency and Assignment Group for the new Incident",
fields: [{
//Impact Choice Field
type: 'choice',
name: 'Impact',
label: getMessage('Please select the impact.'),
mandatory: true,
choices: impactChoices,
value: impactChoices[2].value,
displayValue: impactChoices[2].displayValue
},
{
//Urgency Choice Field
type: 'choice',
name: 'Urgency',
label: getMessage('Please select the urgency.'),
mandatory: true,
choices: urgencyChoices,
value: urgencyChoices[2].value,
displayValue: urgencyChoices[2].displayValue
},
{
//Assignment Group Reference Field
type: 'reference',
name: 'assignment_group',
label: getMessage('Please select an assignment group.'),
mandatory: true,
reference: 'sys_user_group',
referringTable: 'interaction',
referringRecordId: g_form.getUniqueValue(),
value: answer.value,
displayValue: answer.display
}
],
size: 'md'
}).then(function(fieldValues) {
var impact = fieldValues.updatedFields[0].value;
var urgency = fieldValues.updatedFields[1].value;
var group = fieldValues.updatedFields[2].value;
//Save the interaction before creating an incident
save(group, impact, urgency);
});
}
}
function save(group, impact, urgency) {
//If the interaction is already closed just create a new incident, do not save the interaction
if (g_form.getValue('state') == ('closed_complete' || 'closed_abandoned')) {
createIncident(group, impact, urgency);
//Otherwise save the interaction then create the incident.
} else {
g_form.save().then(function() {
createIncident(group, impact, urgency);
});
}
}
//Call the Script include to generate the incident.
function createIncident(group, impact, urgency) {
var ga = new GlideAjax('createIncident');
ga.addParam('sysparm_name', 'createIncidentFunction');
ga.addParam('sysparm_group', group);
ga.addParam('sysparm_impactChoice', impact);
ga.addParam('sysparm_urgencyChoice', urgency);
ga.addParam('sysparm_sysID', g_form.getUniqueValue());
ga.getXMLAnswer(callBackFunction);
function callBackFunction(answer) {
//Open the new incident in a new workspace tab.
g_aw.openRecord('incident', answer);
}
}
//Function to call the script include to get the impact and urgency choices
function getChoices(element, table) {
var gA = new GlideAjax("GetChoices");
gA.addParam('sysparm_table_name', table);
gA.addParam('sysparm_field_name', element);
gA.addParam('sysparm_name', 'getChoiceOptions');
gA.getXML(getChoices);
var choices = [];
function getChoices(response) {
choicesObj = {};
var answer = response.responseXML.documentElement.getAttribute("answer");
choicesObj = JSON.parse(answer);
for (var key in choicesObj.choices) {
var choicesSet = {
displayValue: choicesObj.choices[key].label,
value: parseInt(choicesObj.choices[key].value)
};
choices.push(choicesSet);
}
}
return choices;
}
Script Include:
createIncidentFunction: function() {
var sysID = this.getParameter('sysparm_sysID');
var group = this.getParameter('sysparm_group');
var impact = parseInt(this.getParameter('sysparm_impactChoice'));
var urgency = parseInt(this.getParameter('sysparm_urgencyChoice'));
//Pull the interaction's information
var ims = new GlideRecord('interaction');
ims.get(sysID);
var canCreateIncident = false;
var close_note = "An incident was submitted for this interaction. See related records.";
//If there is an active chat, do not allow for an incidnet to be created.
if ((ims.type == 'chat' && ims.active == true && ims.state != 'wrap_up')) {
gs.addErrorMessage("Please end the chat before creating an incident");
} else {
if ((ims.isNewRecord() && ims.canCreate()) || (!ims.isNewRecord() && ims.canWrite())) {
//Set interaction fields.
if (ims.active) {
ims.u_incident_submitted = true;
ims.state = 'closed_complete';
ims.assigned_to = gs.getUserID();
ims.u_close_notes = close_note;
canCreateIncident = ims.update();
} else {
ims.u_incident_submitted = true;
ims.u_close_notes = close_note;
}
canCreateIncident = ims.update();
} else {
canCreateIncident = true;
}
if (canCreateIncident) {
//Initialize new incident record.
var inc = new GlideRecord("incident");
inc.initialize();
//Set Incident fields based on the the information in the interaction.
inc.impact = impact;
inc.urgency = urgency;
inc.caller_id = ims.opened_for;
inc.short_description = ims.short_description;
inc.u_call_back_number = ims.u_call_back_number;
inc.location = ims.location;
inc.category = ims.category;
inc.subcategory = ims.subcategory;
inc.cmdb_ci = ims.u_cmdb_ci;
inc.description = ims.u_description;
inc.u_asset_tag = ims.u_asset_tag;
inc.assignment_group = group;
inc.work_notes = ims.work_notes;
if (ims.type == 'chat') {
inc.contact_type = 'virtual_agent';
}
//Insert the new incident and save the SysID.
var incSysId = inc.insert();
//If the incident was created link it to the interaction.
if (incSysId) {
var interactionRelatedGR = new GlideRecord("interaction_related_record");
interactionRelatedGR.initialize();
interactionRelatedGR.interaction = ims.sys_id;
interactionRelatedGR.document_table = 'incident';
interactionRelatedGR.document_id = incSysId;
interactionRelatedGR.insert();
}
//Copy attachments from the interaction to the incident.
new InteractionRelationshipUtil().copyAttachments(ims, inc);
}
}
return incSysId;
},
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 08:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 08:53 AM
I found my issue, it was with a before query business rule.