Service Catalog

indrajeetma
Tera Guru

Implement a rule that when a new "Service Catalog Request" is submitted with a high priority , it checks for any open incidents from the same user in the past 30 days. If more than three such incidents are found, change the priority of the new request to "Priority 2" .|


give me step by step solution

1 ACCEPTED SOLUTION

Akash4
Kilo Sage
Kilo Sage

Hello,

Easy & quicker way (always) is via Business Rules.

Write a BR on Request table, probably Async (best practice), Insert with a condition: Priority = High

In the Script section, add these lines & edit accordingly:

(function executeRule(current, previous) {
var gr = new GlideRecord('incident');
var thirtyDaysAgo = new GlideDateTime();
gr.addDaysUTC(-30);

gr.addActiveQuery();
gr.addQuery('caller_id',current.requested_for);
gr.addQuery('opened_at','>=',thirtyDaysAgo);
gr.query();

var incCount = 0;
while (gr.next()) {
incCount++;
if (incCount > 3) {
current.priority = <Medium> or <priority 2>; //edit here

current.update();}}
})(current, previous);

 

if you switch to Before BR then avoid the last line - current.update(), instead write “break;”

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

View solution in original post

1 REPLY 1

Akash4
Kilo Sage
Kilo Sage

Hello,

Easy & quicker way (always) is via Business Rules.

Write a BR on Request table, probably Async (best practice), Insert with a condition: Priority = High

In the Script section, add these lines & edit accordingly:

(function executeRule(current, previous) {
var gr = new GlideRecord('incident');
var thirtyDaysAgo = new GlideDateTime();
gr.addDaysUTC(-30);

gr.addActiveQuery();
gr.addQuery('caller_id',current.requested_for);
gr.addQuery('opened_at','>=',thirtyDaysAgo);
gr.query();

var incCount = 0;
while (gr.next()) {
incCount++;
if (incCount > 3) {
current.priority = <Medium> or <priority 2>; //edit here

current.update();}}
})(current, previous);

 

if you switch to Before BR then avoid the last line - current.update(), instead write “break;”

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.