Identify all the field changes in a table record

Ra_l Ruvalcaba
Tera Contributor

Hi, i am trying to identify all the changes in a lot of records in a specify table, in this case cmdb_ci_server, the field is state, the discovery made its changes but i need to know the amount of all the records that update the state field, i was searching in the sys_history_line table, but i can't search the records in a massive way, only one by one, for example "state is one of", my question is if exist another way to identify all the records with these changes by field in a table and the date?

 

Regards

Thank you

3 REPLIES 3

Amit Gujarathi
Giga Sage
Giga Sage

HI @Ra_l Ruvalcaba ,
I trust you are doing fine.
To identify all the changes in the "state" field of the "cmdb_ci_server" table and obtain the count of records that have been updated, you can use a GlideRecord query in ServiceNow.

// Create a new GlideRecord instance for the cmdb_ci_server table
var gr = new GlideRecord('cmdb_ci_server');

// Add a query condition for the desired state values
gr.addQuery('state', 'IN', ['value1', 'value2', 'value3']); // Replace 'value1', 'value2', 'value3' with your desired state values

// Add an additional query condition for the desired date range, if needed
gr.addQuery('sys_updated_on', '>=', 'yyyy-MM-dd 00:00:00'); // Replace 'yyyy-MM-dd' with your desired start date

// Add another query condition for the desired date range, if needed
gr.addQuery('sys_updated_on', '<=', 'yyyy-MM-dd 23:59:59'); // Replace 'yyyy-MM-dd' with your desired end date

// Execute the query
gr.query();

// Get the count of records that match the query
var recordCount = gr.getRowCount();

// Print the count of updated records
gs.info('Number of records updated: ' + recordCount);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



The query takes the updates anyway you update another field, for example i updated the state in april and the ip address in may, with this query i get the records updated in may with this state, but not the change of the state