i am looking for fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
I need to perform below logic
For each record in std_change_record_producer [created != 12345] which has 12345's version data, check the correct version in std_change_producer_version and update in std_change_record_producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @GURUMURTHYG ,
Directly updating the std_change_record_producer table via script is generally not recommended for versioning because it bypasses the Standard Change governance workflow.
Standard Changes in ServiceNow are governed by a proposal and approval process.
Using a script to force updates directly on this table can lead to data inconsistencies and audit failures.c
If still you want to proceed,
here is sample code:
var grRecordProducer = new GlideRecord('std_change_record_producer');
grRecordProducer.addQuery('std_change_producer_version', '!=', '12345');
grRecordProducer.query();
gs.info('Total records found: ' + grRecordProducer.getRowCount());
while (grRecordProducer.next()) {
var templateId = grRecordProducer.getValue('template'); // Assuming 'template' maps to the producer
var grVersion = new GlideRecord('std_change_producer_version');
grVersion.addQuery('std_change_producer', templateId);
grVersion.orderByDesc('sys_created_on');
grVersion.query();
if (grVersion.next()) {
grRecordProducer.setValue('version', grVersion.sys_id);
grRecordProducer.setWorkflow(false);
grRecordProducer.update();
gs.info('Updated std_change_record_producer ' + grRecordProducer.getValue('name') + ' with correct version: ' + grVersion.sys_id);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
hai @GURUMURTHYG
You can handle this requirement using a fix script by iterating through the records in std_change_record_producer, identifying the correct version from std_change_producer_version, and updating it accordingly.
Below is a simple approach:
