- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 10:54 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:10 AM
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;”
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 11:10 AM
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;”
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.