0% found this document useful (0 votes)
2 views4 pages

Automate Problem Creation from Incident

The document outlines a process for creating a Problem record from an Incident when the priority changes, ensuring no duplicate Problems are created. It includes functions for checking existing Problems, counting them, and creating new ones with relevant fields copied from the Incident. Additionally, it describes a script include and business rule to automate this process in a system using GlideRecord for database interactions.

Uploaded by

Sahil Shinde
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Automate Problem Creation from Incident

The document outlines a process for creating a Problem record from an Incident when the priority changes, ensuring no duplicate Problems are created. It includes functions for checking existing Problems, counting them, and creating new ones with relevant fields copied from the Incident. Additionally, it describes a script include and business rule to automate this process in a system using GlideRecord for database interactions.

Uploaded by

Sahil Shinde
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Update an Incident → if priority changes, a Problem should be created (with common

fields copied).

Test again by toggling priority:

Example: Change from P3 → P2 → Problem created.

Then change back from P2 → P3 → Should it create another Problem? Or block


duplicates?
👉 createProblemFromIncident: function(current) {
var prb = new GlideRecord('problem');
[Link]();
prb.short_description = current.short_description;
[Link] = [Link];
prb.cmdb_ci = current.cmdb_ci;
prb.assignment_group = current.assignment_group;
var problemSysId = [Link]();
current.problem_id = problemSysId;
return problemSysId;
},

--> var prbCreator = new ACS_utilities_PrbCreationFromInc();


[Link](current);

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

👉 getCount: function(table, field, value) {


var count = 0;
var grProb = new GlideAggregate(table);
[Link](field, value);
[Link]('COUNT');
[Link]();

if ([Link]()) {
count = [Link]('COUNT');
}
return count;

--> var obj = new ACS_Get_Count();


var count = [Link]('problem','cmdb_ci',current.cmdb_ci);
[Link]("Problem count for this CI: " + count);

-----------------------------------------------------------------------------------
-----------------------
if ([Link]()) {

// Check if a Problem already exists for this Incident


var probCheck = new GlideRecord('problem');
[Link]('incident_reference', [Link]);
[Link]();

if (![Link]()) {

//only create problem if dont exist


var grProblem = new GlideRecord('problem');
[Link]();
grProblem.short_description = current.short_description;
[Link] = [Link];
grProblem.cmdb_ci = current.cmdb_ci;
grProblem.assignment_group = current.assignment_group;
grProblem.correlation_id = [Link];
[Link]();
}
}

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

if ([Link]()) {

// Check if a Problem already exists for this Incident


var probCheck = new GlideRecord('problem');
[Link]('incident_reference', [Link]); // custom field
on Problem
[Link]();

if (![Link]()) { // Only create if no existing Problem

// Create new Problem record


var grProblem = new GlideRecord('problem');
[Link]();
grProblem.short_description = current.short_description;
[Link] = [Link];
grProblem.cmdb_ci = current.cmdb_ci;
grProblem.assignment_group = current.assignment_group;

// Link Problem back to Incident


grProblem.incident_reference = [Link]; // custom reference
field
var problemSysId = [Link]();

// Link Incident to the Problem


current.problem_id = problemSysId; // custom reference field on
Incident
}
}

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

(function executeRule(current, previous) {

// Trigger only if Priority changed AND no Problem linked yet


if ([Link]() && current.problem_id.nil()) {

var prb = new GlideRecord('problem');


[Link]();
prb.short_description = current.short_description; // copy from Incident
[Link] = [Link]; // copy from Incident
prb.cmdb_ci = current.cmdb_ci;
prb.assignment_group = current.assignment_group;

// Insert the Problem


var problemSysId = [Link]();

// Link Incident to Problem


current.problem_id = problemSysId; // Reference field on Incident
// No need for [Link]() because this is a before update BR
}

})(current, previous);

------------script include + BR

var ACS_utilities_PrbCreationFromInc = [Link]();


ACS_utilities_PrbCreationFromInc.prototype = {
initialize: function() {},

// Method to create Problem from Incident


createProblemFromIncident: function(current) {
// Only run if priority changed
if ([Link]()) {

var prb = new GlideRecord('problem');


[Link]();
prb.short_description = current.short_description;
[Link] = [Link];
prb.cmdb_ci = current.cmdb_ci;
prb.assignment_group = current.assignment_group;

var problemSysId = [Link]();

// Link the Problem to the Incident


current.problem_id = problemSysId;

return problemSysId; // return sys_id of Problem


}

return null; // nothing created


},

type: 'ACS_utilities_PrbCreationFromInc'
};

*************BR for above script include*************

(function executeRule(current, previous /*null when async*/) {

var prbCreator = new ACS_utilities_PrbCreationFromInc();


[Link](current);

})(current, previous);

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

pro_create : function(current){
[Link]("pro_create");
var grProblem = new GlideRecord('problem');
[Link]();
grProblem.short_description = "Auto-created Problem for Critical
cmdb_ci";
grProblem.cmdb_ci = current.cmdb_ci;
[Link] = [Link];
[Link] = " this problem auto created if incidents
cmdbi_ci is crititca";
var p = [Link]();
[Link](p);
return p;
},

var obj = new ACS_Scripts().pro_create(current);


[Link]("a problem ticket auto created");
[Link](obj);
current.problem_id = obj;
[Link]();

You might also like