need help in business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 11:52 AM - edited ‎11-01-2023 11:54 AM
I have a business rule which runs on the TASK table, conditions are when the state of the particular TASK based on the short description changes to closed complete.
In the task, there is a field with the backend value 'request_item.configuration_item', which is referenced to Computer System table. It stores the computer assigned to the requestor. So here I am querying the table and finding that system and then updating the field in that form. But it's not updating.
With the logs added, I am getting this
'[object GlideRecord] fad58863134aab405d3870146144b0a9 TEST
(function executeRule(current, previous /*null when async*/ ) {
var computer = current.request_item.configuration_item;
var computerSystem = new GlideRecord('u_cmdb_ci_computersystem');
computerSystem.addQuery('name', computer);
computerSystem.query();
gs.log(computerSystem + computer + 'TEST');
while (computerSystem.next()) {
computerSystem.setValue('install_status', 'Return');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 12:39 PM - edited ‎11-01-2023 12:39 PM
If that log represents the correct record on the custom table, add a line within the while block to save the update:
computerSystem.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 08:29 PM
you should query with sysId and use update method
(function executeRule(current, previous /*null when async*/ ) {
var computer = current.request_item.configuration_item;
var computerSystem = new GlideRecord('u_cmdb_ci_computersystem');
computerSystem.addQuery('sys_id', computer);
computerSystem.query();
if (computerSystem.next()) {
computerSystem.setValue('install_status', 'Return'); // use correct choice value for the field
computerSystem.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 09:54 PM
HI @sn37 ,
I trust you are doing great.
Please find updated script as given below
(function executeRule(current, previous /*null when async*/) {
// Check if the state of the task has changed to 'Closed Complete'
if (current.state.changesTo('Closed Complete')) {
// Get the 'configuration_item' value from the 'request_item' field
var computer = current.request_item.configuration_item.getDisplayValue();
// Query the 'u_cmdb_ci_computersystem' table to find the matching computer system
var computerSystem = new GlideRecord('u_cmdb_ci_computersystem');
computerSystem.addQuery('name', computer);
computerSystem.query();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi