- 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-06-2024 04:52 AM
Please do check @Community Alums
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2024 05:42 AM
Hi @Hitesh Ramba ,
Did you checked Updated check box and type is before ?
Like this
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-06-2024 04:58 AM
Why are you asking the same question three times?
What did you already try yourself? What kind of assignment is this? Did you try something already, or are you just asking others to do your work for them?
https://www.servicenow.com/community/product-launch-forum/scripting-assignment/td-p/2918571
https://www.servicenow.com/community/product-launch-forum/incident-task/td-p/2919123
https://www.servicenow.com/community/product-launch-forum/incident-not-allowed-to-close/td-p/2919124
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark