script needed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 11:43 AM
HI All,
there was an issue happened and for the few incident the caller id got blank . when i see the incident history the caller id is blank. Now need to update the caller id on the incident from history table
I need a script for the condition on the incident history table .
need to find out the incident which has the caller id is empty and take the Caller Old with latest updated time and insert in caller id field .
Do you have the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 02:25 PM
This script will do that:
var incGR = new GlideRecord('incident');
incGR.addNullQuery('caller_id');
incGR.query();
while (incGR.next()) { //loops through ALL incidents with a blank Caller
var histGR = new GlideRecord('sys_history_line');
histGR.addQuery('set.id', incGR.getValue('sys_id'));
histGR.addQuery('field', 'caller_id');
histGR.addNotNullQuery('old_value');
histGR.orderByDesc('sys_created_on');
histGR.setLimit(1);
histGR.query();
if (histGR.next()) { //returns the most recent record which has an old value for Caller
incGR.setValue('caller_id', histGR.getValue('old_value'));
incGR.setWorkflow(false); //do not run Business Rules on update
incGR.autoSysFields(false); //do not update sys_updated_on, sys_updated_by,... fields
incGR.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 02:10 AM - edited 09-06-2024 02:58 AM
Hi - when i run this script i am getting below error .@Brad Bowman i placed gs.print and did not enter into the if loop
i need to add the below query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 04:06 AM
What is line 13 on your script? Since my script ran fine for me, that could point to bad data retrieved on the history_line, or something in the encoded query. If you haven't done so, remove the incGR.addNullQuery line, and manually filter an incident list per your encoded query criteria to copy the query to the script. This probably isn't impacting the results, but it should just be ...caller_idISEMPTY... in an encoded query.
caller_idISEMPTY^active=true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 06:06 AM