Issue with gliding sys_audit table table from workflow editor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:33 AM
Hello community,
Requirement : Glide sys_audit table to fetch the worknotes contains specific context and update the state of that incident record .
Below script is working in the background script but the same script is not working from workflow editor .
while (gr.next()) condition is getting false when it run from worfklow editor. Can anyone point me what is worng with script ?
var sysId = 'YOUR_DOCUMENT_KEY_HERE'; // Replace 'YOUR_DOCUMENT_KEY_HERE' with the actual document key
var noteText = 'YOUR_NOTE_TEXT_HERE'; // Replace 'YOUR_NOTE_TEXT_HERE' with the note text you want to search
var gr = new GlideRecord('sys_audit');
var updatedBy;
var updatedOn;
gr.addQuery('documentkey', sysId);
gr.addQuery('fieldname', 'work_notes');
gr.addQuery('newvalue', 'CONTAINS', noteText);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
updatedBy = gr.getValue('sys_created_by');
updatedOn = gr.getValue('sys_created_on');
// Do something with the retrieved values
gs.print('Audit record updated by: ' + updatedBy);
gs.print('Updated on: ' + updatedOn);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:50 AM
Hi,
Can you please explain your requirement?
On which table your Workflow is running?
What values you are trying to fetch from sys_audit table?
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:52 AM
If you want data related with incident then your workflow should be on Incident table.
and update your script like below:
var sysId = current.sys_id.toString();
var noteText = 'YOUR_NOTE_TEXT_HERE'; // Replace 'YOUR_NOTE_TEXT_HERE' with the note text you want to search
var gr = new GlideRecord('sys_audit');
var updatedBy;
var updatedOn;
gr.addQuery('documentkey', sysId);
gr.addQuery('fieldname', 'work_notes');
gr.addQuery('newvalue', 'CONTAINS', noteText);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
updatedBy = gr.getValue('sys_created_by');
updatedOn = gr.getValue('sys_created_on');
// Do something with the retrieved values
gs.print('Audit record updated by: ' + updatedBy);
gs.print('Updated on: ' + updatedOn);
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:55 AM
Hi Anil ,
Thanks for the reply .
Workflow is running on incident table , when the incident is created workflow is triggering for the current incident record for the same record i need to fetch the worknotes which contains particular text , to fetch that particular worknote im gliding the sys_ audit table
Thanks
Varshini