Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get the data from sysevent table to my custom table.

Suresh_32
Tera Expert

We want get data (insert/update records) from Event(sysevent) table to my custom table.

 

Created BR on table is 'sysevent' and after insert/update BR.

 

 var oldRecord = new GlideRecord("sysevent");
 oldRecord.addQuery('nameLIKElogin^ORnameLIKElogout'); // only we want login and Logout records from event table.
 oldRecord.query();
 while(oldRecord.next())
    var newRecord = new GlideRecord("u_newtable"); //my custom table
    newRecord.initialize();
    newRecord.u_created = current.sys_created_on;
    newRecord.u_name = current.name;
    newRecord.u_parm1 = current.parm1;
    newRecord.insert();
//    newRecord.update();
11 REPLIES 11

Ramesh_Naidu
Mega Guru

Hi @Suresh_32 ,

 

You can write a Async business rule, as there will be many records that will be created on the events table. I have attached sample example for reference.

Ramesh_Naidu_0-1714636290387.png

Ramesh_Naidu_1-1714636304086.png

Thankyou.

 

Hi @Ramesh_Naidu ,

Thank you for reply, updated my business rule but records are not inserted in my custom table.

Hi @Suresh KSB ,

 

Have you tried running the same code from the background script? It might be a cross-scope issue.

 

Thankyou,

Ramesh

Hi Ramesh,

 

Yes Background script is working fine, how to resolve the cross-scope issue.

 
 
var oldRecord = new GlideRecord("sysevent");
oldRecord.addQuery('nameLIKElogin^ORnameLIKElogout');
//nameLIKElogin
oldRecord.query();
while(oldRecord.next())
{
    var newRecord = new GlideRecord("u_newtable");
    newRecord.initialize();
    newRecord.u_created = oldRecord.sys_created_on;
    newRecord.u_name = oldRecord.name;
    newRecord.u_parm1 = oldRecord.parm1;
 
    newRecord.insert();
}