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-06-2024 06:23 AM
Oh, I thought the error was pointing to line 13. At least make the two other changes I talked about, verify the encoded query is correct via a manual filtering of the list view, then if you're still getting the date error you'll have to add more gs.print lines to determine which incident or sys_history_line record has an invalid date. task_for is not the name of a column on the incident table. If the encoded query is invalid the entire thing will be ignored and the first random 50 records will be returned by the GR.
var incGR = new GlideRecord('incident');
incGR.addEncodedQuery('u_markerLIKEpb_mig^caller_idISEMPTY^task_forISEMPTY^stateIN1,2,3,6');
//incGR.addQuery('number','INC4489634');
incGR.setLimit(50);
incGR.query();
while(incGR._next())
{
var histGR = new GlideRecord('sys_history_line');
var incSysID = incGR.getValue('sys_id');
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);
gs.print("Line 13");
histGR.query();
while (histGR.next()) {
var oldValue = histGR.getValue('old_value');
if(oldValue)
{
incGR.setValue('caller_id', oldValue);
incGR.setValue('task_for', oldValue);
incGR.setWorkflow(false);
incGR.autoSysFields(false);
incGR.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 08:51 AM
I modified my script and it was not working now . Please find my comment on the script it is not entering in to the while itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 11:37 AM
This shows an error returning records from your sys_history_line table. I'm not sure why you see this message repeated so many times when you have an incGR limit of 5. Try isolating the script to just this section with a hard-coded sys_id of an incident record that you know fits the criteria to see if you can get sys_history_line to return any records. It still looks like you have some data corruption in the sys_history_line table.
var histGR = new GlideRecord('sys_history_line');
var incSysID = <<sys_id>>;
histGR.addEncodedQuery("set.id="+incSysID+"^field=caller_id^old!=NULL");
histGR.orderByDesc('sys_created_on');
histGR.setLimit(1);
gs.print("Line 13");
histGR.query();
while (histGR.next()) { // it is not entering in to this while itself
gs.print("Line 14");
}