to create a problem through incident

nitinku
Tera Contributor

Hi, I want to create a problem through an incident, like if I am getting more than 10 incidents with some same configuration, then the problem will be automatically created. 

 

So, for this, I have to create business rules and make custom logic for this functionality, or we have some out-of-the-box things to get the work done. 

 

Thank you...

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @nitinku ,

 

a. If your requirement on dynamic " same configuration" with multiple fields,

You need to go with Similarity incidents using predictive intelligence

Refer: OOB Similarity definition on incident.

 

b. If your requirement is with same field "Same configuration" like cmdb_ci field in incident,

Then create a After Update BR.

Sample code:

 

(function executeRule(current, previous /*null when async*/) {
if (!current.cmdb_ci) {
return;
}

var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT');
agg.addQuery('active', true);
agg.addQuery('cmdb_ci', current.cmdb_ci);
agg.query();

var activeCount = 0;
if (agg.next()) {
activeCount = parseInt(agg.getAggregate('COUNT'), 10);
}

var threshold = 10;

if (activeCount >= threshold) {
var existingProblem = new GlideRecord('problem');
existingProblem.addQuery('cmdb_ci', current.cmdb_ci);
existingProblem.addActiveQuery(); // Checks if the problem is still open
existingProblem.query();

if (!existingProblem.next()) {
var problem = new GlideRecord('problem');
problem.initialize();
problem.short_description = 'Automatic Problem: Multiple (' + activeCount + ') incidents reported for CI: ' + current.cmdb_ci.getDisplayValue();
problem.description = 'A problem was automatically created because there are ' + activeCount + ' active incidents related to configuration item: ' + current.cmdb_ci.getDisplayValue();
problem.cmdb_ci = current.cmdb_ci;
problem.insert();
}
}
})(current, previous);

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

PoonkodiS
Giga Sage

Hi @nitinku 

Automatically create problem when more than 4 inci... - Page 2 - ServiceNow Community

refer this solution and change the script according to your requirement