automate calculation of problem end date for RC Analysis Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:05 AM
Hi All,
1. we have a requirement like auto populated problem due date when incident is p1, problem due date should be+7working days.(Monday to Friday)
2. if incident is p2 problem due date should be +12 working days(Monday to Friday).
3. problem due date should auto populated when problem state is Root cause analysis.
4. when we create problem task from the same problem table, also populated problem_task due date value.
Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 08:51 PM
Then your business rule should be on incident.
Table : incident
When: after
Insert: clicked
Update: clicked
condition: problem is not empty && (priority changes to 1-Critical || priority changes to 2-High)
var problem = current.problem_id;
var priority = current.priority;
if(problem && (priority == 1 || priority == 2){
var date = new GlideRecord('problem');
date.addQuery('sys_id', problem);
date.addQuery('state', '103'); // state is tRoot Cause Analysis
date.query();
if(date.next()){
var days = 7;
if(priority ==2){
days = 12;
}
var created = new GlideDateTime(current.sys_created_on); // this one update if you want from problem created date (date.sys-created_on)
var duration = new GlideDuration(1000*60*60*8*days);
var schdule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
var duedate = schdule.add(created,duration);
date.due_date = duedate;
date.update();
}
}
As said earlier update 8 with 24 if your schedule is 24 hours one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:52 PM
Hi @harshav,
I have tried with above script but it didn't work
Script:
(function executeRule(current, previous /*null when async*/ ) {
var problem = current.problem_id;
var priority = current.priority;
if (problem && (priority == 1 || priority == 2)) {
var date = new GlideRecord('problem');
date.addQuery('sys_id', problem);
date.addQuery('state', '103'); // state is tRoot Cause Analysis
date.query();
if (date.next()) {
var days = 7;
if (priority == 2) {
days = 12;
}
var created = new GlideDateTime(current.sys_created_on);
var duration = new GlideDuration(1000 * 60 * 60 * 24 * days);
var schdule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
var duedate = schdule.add(created, duration);
date.due_date = duedate;
date.update();
}
}
})(current, previous);
Result: