Issue with gliding sys_audit table table from workflow editor

varshinin
Tera Contributor

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);
}

3 REPLIES 3

Anil Lande
Kilo Patron

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?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

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);
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

varshinin
Tera Contributor

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