We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Get the date when the state was changed to "Approved"

HelloCAD
Tera Contributor

Hi,

I need to get the date when the "State" of the record was changed to "Approved".

I created a Business Rule to capture the date in a Date field when the state changes, but for old records is there way to get the date. I tried GlideRecord for "sys_history_line" table but that does not work.

 

The state does not change from the sysapproval_approver table. It is changed when required users sign a document via a 3rd party integration.

PS: I can see the date in the Work Notes.

Thanks.

4 REPLIES 4

RAHUL YADAV9
Mega Guru

When you are glide recording sys history line table instead of checking set=sysid Check set.id=sysid of the incident or ritm.

Feel free to mark correct and helpful.

HelloCAD
Tera Contributor

Yes, I used seet.id=the sys_id of the record.

The thing is, the table had around 60 records and it returned only the dates for around 15 records. For others, it showed undefined. Though if I open the record and view its history, it's there.

var seh = new GlideRecord("sys_history_line");

seh.addQuery('set.id', se.sys_id);

seh.addEncodedQuery("label=State^new=Approved");

seh.query();

 

if (seh.next()){

up = new GlideDateTime(seh.update_time)

}

Instead of quering sys_history_line why not take updated time of the record.

I am assuming when record is Approved that will be the final update that has happened on the record.

Something as below

var approvalis=new GlideRecord('sysapproval_approver');
approvalis.addQuery('state','approved');
approvalis.query();
while(approvalis.next())
{
gs.print('Record was approved at '+approvalis.sys_updated_on.getDisplayValue());
}

HelloCAD
Tera Contributor

The state does not change from the sysapproval_approver table. It is when required users sign a document via a 3rd party integration.