- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 12:45 AM
Hi everyone,
I created a simple BR to pass the sys id of the latest records from the rm_relaease table to a script include to use the sys id in the script include for further updates.
here is the BR:
(function executeRule(current, previous /*null when async*/) {
// Get the latest record from rm_release table
var latestReleaseRecord = new GlideRecord('rm_release');
latestReleaseRecord.orderByDesc('sys_created_on');
latestReleaseRecord.addEncodedQuery('numberSTARTSWITHRLSE');
latestReleaseRecord.setLimit(1);// Order by sys_created_on to get the latest record
latestReleaseRecord.query();
// Check if a record exists and retrieve the latest sys_id
while (latestReleaseRecord.next()) {
var parentSysID = latestReleaseRecord.getValue('sys_id'); // Get the sys_id of the latest record
gs.addInfoMessage(parentSysID);
// Call the Script Include
new REupdateReleasePhaseRecords().updateRecords(parentSysID); // Call the function and pass sys_ids
}
})(current, previous);
And here the script include:
var REupdateReleasePhaseRecords = Class.create();
REupdateReleasePhaseRecords.prototype ={
initialize: function() {},
updateRecords: function(parentSysID) {
// Get the current record
//gs.sleep(3000);
gs.info('Script include updateRecords called with sys_id: ' + parentSysID);
var gr = new GlideRecord('rm_release_phase');
gr.addEncodedQuery('parent.sys_idSTARTSWITH' + parentSysID);
gr.query();
// Loop through the related rm_release_phase records
while (gr.next()) {
gs.info('Updating record: ' + gr.sys_id);
// Update the desired fields in the rm_release_phase records
gr.start_date = ''; // clear
gr.end_date = ''; // clear
gr.update();
}
},
type: 'REupdateReleasePhaseRecords'
};
I called the BR part in the background script and get the following error:
Background message, type:info, message: 808262661b30da50f66a96859b4bcb91
*** Script: Script include updateRecords called with sys_id: undefined
Can you help me what could be the problem?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 01:36 AM
Hello @JohnDF
Please make the change in below line of code and remove the STARTSWITH in the query because you are only get the sys_id of the record so can only query like gr.addEncodedQuery('parent.sys_id'+ parentSysID)
gr.addEncodedQuery('parent.sys_idSTARTSWITH' + parentSysID);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:04 AM
Hey Abhishek can you please check the function on line 12 the function is "getUniqueValue();" but in script I can see it as "getUniqeValue()" where u is missing , Please check & try again !
Please mark my answer as accepted solution and give thumbs up, if it helps you.