- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 05:40 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 11:57 PM
Hi @MihirG ,
When we are adding incidents to Problem record, it updates the Problem[problem_id] on the incident record.
So, the business rule is to be written on the Incident record.
First query the incident table with all incidents with similar Problem[problem_id] associated and update the count on the problem record.
When: After Insert/Update
Condition: Problem changes
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//gs.addInfoMessage('Previous: ' + previous.problem_id);
//gs.addInfoMessage('current ' + current.problem_id);
if(current.problem_id != ''){
var id = current.problem_id; // When incident is added
}else{
var id = previous.problem_id; // When incident is removed
}
var grInc = new GlideRecord('incident');
grInc.addQuery('problem_id',id);
grInc.query();
//gs.addInfoMessage(grInc.getRowCount());
var grPRB = new GlideRecord('problem');
grPRB.addQuery('sys_id',id);
grPRB.query();
if(grPRB.next()){
grPRB.u_incidentcount = grInc.getRowCount();
grPRB.update();
}
})(current, previous);
If this information helps you, kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 11:57 PM
Hi @MihirG ,
When we are adding incidents to Problem record, it updates the Problem[problem_id] on the incident record.
So, the business rule is to be written on the Incident record.
First query the incident table with all incidents with similar Problem[problem_id] associated and update the count on the problem record.
When: After Insert/Update
Condition: Problem changes
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//gs.addInfoMessage('Previous: ' + previous.problem_id);
//gs.addInfoMessage('current ' + current.problem_id);
if(current.problem_id != ''){
var id = current.problem_id; // When incident is added
}else{
var id = previous.problem_id; // When incident is removed
}
var grInc = new GlideRecord('incident');
grInc.addQuery('problem_id',id);
grInc.query();
//gs.addInfoMessage(grInc.getRowCount());
var grPRB = new GlideRecord('problem');
grPRB.addQuery('sys_id',id);
grPRB.query();
if(grPRB.next()){
grPRB.u_incidentcount = grInc.getRowCount();
grPRB.update();
}
})(current, previous);
If this information helps you, kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:37 PM
Thanks