- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 03:57 AM
Hi,
We have created a field called First assigned to incident table. Purpose of the field is to capture the first assignee of the ticket. We have created Business rule it is working for new records. We have to update the existing records. Kindly help me how to update the existing records.
Thanks in Advance !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 05:57 AM
Hi,
example below
if table is audited then you can do this
You can do GlideRecord from following tables,
sys_history_set and sys_history_line
var incident = new GlideRecord('incident');
incident.addQuery('u_first_assigned',''); // give correct field name here
incident.query();
while(incident.next()){
var history = new GlideRecord('sys_history_set');
history.addQuery('id',incident.getValue('sys_id'));
history.query();
history.next();
var auditH = new GlideRecord('sys_history_line');
auditH.addQuery('set',history.getValue('sys_id'));
auditH.addEncodedQuery("field=assigned_to^newISNOTEMPTY^oldISEMPTY"); // new is not epmty and old is empty
auditH.query();
if(auditH.next()){
incident.u_first_assigned = auditH.new_value; // give correct field name here
incident.update();
}
}
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 04:06 AM
You can use background script and either use standard GlideRecord +query + iteratation or GlideMultipleUpdate - doing the same but easier to do and (I hope) faster to use
var gMult = GlideMultipleUpdate('<table>');
gMult.addQuery('<field>', <value>);
gMult.setValue('<field2>', <value2>);
gMult.execute();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 04:08 AM
Hi,
for older records you need to check sys_audit table or sys_history_line table where previous information is stored.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 05:11 AM
Hi Ankur,
Kindly help me with the scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 05:57 AM
Hi,
example below
if table is audited then you can do this
You can do GlideRecord from following tables,
sys_history_set and sys_history_line
var incident = new GlideRecord('incident');
incident.addQuery('u_first_assigned',''); // give correct field name here
incident.query();
while(incident.next()){
var history = new GlideRecord('sys_history_set');
history.addQuery('id',incident.getValue('sys_id'));
history.query();
history.next();
var auditH = new GlideRecord('sys_history_line');
auditH.addQuery('set',history.getValue('sys_id'));
auditH.addEncodedQuery("field=assigned_to^newISNOTEMPTY^oldISEMPTY"); // new is not epmty and old is empty
auditH.query();
if(auditH.next()){
incident.u_first_assigned = auditH.new_value; // give correct field name here
incident.update();
}
}
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader