- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 06:25 AM
HI , I have a requirement using scripting have to make this requirement possible ,kindly help me int it...
1.Incident should be auto resolved when all the incident tasks are closed.
2.Incidents should not be allowed to resolve if there are any incident tasks in an open state , and it should throw an alert saying."Please close incident taks",before resolving the incidents.
3.Create a "Best Contact Number" field on the incident form, which should allow only a 10- digit number and auto populate the "Best Contact Number" and "Location" values based on the caller selection from the user tabel.
4.When change is closed all related incident and catalog tasks should be auto-closed and all the worknotes must be updated saying "this has been closed by change rquest : #number."
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 11:22 AM
Hi @Hitesh Ramba ,
I tired your problem in my PDI and it works for me please check kbelow
1.Incident should be auto resolved when all the incident tasks are closed.
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.sys_id);
gr.addQuery('state', '!=', 3);
gr.query();
if(gr.next()) {
gs.addErrorMessage('Incident Can not close because incident task is not closed');
current.setAbortAction(true);
}else{
gs.log('close');
current.setValue('state', 7);
}
2.Incidents should not be allowed to resolve if there are any incident tasks in an open state , and it should throw an alert saying."Please close incident taks",before resolving the incidents.
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', 'current.sys_id');
gr.addQuery('state', 1); // open
gr.query();
if(gr.next()) {
gs.addErrorMessage('Please close incident taks,before resolving the incidents.' );
current.setAbortAction(true);
}
else{
current.state = 6 // resolved
}
4. When change is closed all related incident and catalog tasks should be auto-closed and all the worknotes must be updated saying "this has been closed by change rquest : #number."
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var incgr = new GlideRecord('incident');
incgr.addQuery('parent', current.sys_id);
incgr.query();
gs.print(incgr.getRowCount());
while(incgr.next()){
incgr.setValue('state', 7);
incgr.setValue('comments','this has been closed by change rquest by ' + current.number);
}
var taskgr = new GlideRecord('sc_task');
taskgr.addQuery('parent', current.sys_id);
taskgr.query();
gs.print(taskgr.getRowCount());
while(taskgr.next()){
taskgr.setValue('state', 3)
taskgr.setValue('comments','this has been closed by change rquest by ' + current.number);
}
current.state = 6;
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 04:22 PM
You need to use when to run as before and update
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 11:22 AM
Hi @Hitesh Ramba ,
I tired your problem in my PDI and it works for me please check kbelow
1.Incident should be auto resolved when all the incident tasks are closed.
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.sys_id);
gr.addQuery('state', '!=', 3);
gr.query();
if(gr.next()) {
gs.addErrorMessage('Incident Can not close because incident task is not closed');
current.setAbortAction(true);
}else{
gs.log('close');
current.setValue('state', 7);
}
2.Incidents should not be allowed to resolve if there are any incident tasks in an open state , and it should throw an alert saying."Please close incident taks",before resolving the incidents.
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', 'current.sys_id');
gr.addQuery('state', 1); // open
gr.query();
if(gr.next()) {
gs.addErrorMessage('Please close incident taks,before resolving the incidents.' );
current.setAbortAction(true);
}
else{
current.state = 6 // resolved
}
4. When change is closed all related incident and catalog tasks should be auto-closed and all the worknotes must be updated saying "this has been closed by change rquest : #number."
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var incgr = new GlideRecord('incident');
incgr.addQuery('parent', current.sys_id);
incgr.query();
gs.print(incgr.getRowCount());
while(incgr.next()){
incgr.setValue('state', 7);
incgr.setValue('comments','this has been closed by change rquest by ' + current.number);
}
var taskgr = new GlideRecord('sc_task');
taskgr.addQuery('parent', current.sys_id);
taskgr.query();
gs.print(taskgr.getRowCount());
while(taskgr.next()){
taskgr.setValue('state', 3)
taskgr.setValue('comments','this has been closed by change rquest by ' + current.number);
}
current.state = 6;
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 03:04 PM
Hi Sarthak , I hope the code works but you didnt mention the conditions when to apply , like before or after
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 04:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 04:28 PM
Hi @SAI VENKATESH For all the three?
Also have you checked the 1st code , its not working for me .What is the table I need to mention in the bussiness rule table name?