- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 12:32 PM - edited 11-01-2023 12:52 PM
Hi, I have a business rule which runs on the task table when the particular task state based on the item is changed to closed complete. There is a field in that task 'current.request_item.configuration_item' which is referenced to computer system table. So when task is closed, need to update the field in that record. This is not getting updated.
(function executeRule(current, previous /*null when async*/ ) {
var comp= current.request_item.configuration_item;
var cs= new GlideRecord('u_cmdb_ci_computersystem');
cs.addQuery('name', comp);
cs.query();
while (cs.next()) {
cs.setValue('install_status', 'Return');
cs.update();
}
})(current, previous);
@Ankur Bawiskar @Amit Gujarathi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 01:05 PM - edited 11-01-2023 01:07 PM
What's output of comp in the log, if its reference column then it must be sys_id of record from table [ [u_cmdb_ci_computersystem]
replaced the cs.addQuery('sys_id', comp);
(function executeRule(current, previous /*null when async*/ ) {
var comp= current.request_item.configuration_item;
var cs= new GlideRecord('u_cmdb_ci_computersystem');
cs.addQuery('sys_id', comp); // if comp value is sys_id then apply the query on column sys_id instead of name
cs.query();
while (cs.next()) {
cs.setValue('install_status', 'Return');
cs.update();
}
})(current, previous);
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:07 PM
So its returning sys_id , perfect ..also going inside the while loop ( as TEST1 printed in log ).
are you sure that , install_status which is Integer type select box with choice values, I checked the sys_choice table for this install_status, all values are numeric. Check the same and use the numeric value instead of 'Return'.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 12:51 PM
Hi @2022_ServiceNow ,
You are setting the "install_status" value as "Return" in while loop but not committing/updating that record.
cs.setValue('install_status', 'Return');
cs.update();
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 12:58 PM
@AshishKM I have updated it, still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 01:05 PM - edited 11-01-2023 01:07 PM
What's output of comp in the log, if its reference column then it must be sys_id of record from table [ [u_cmdb_ci_computersystem]
replaced the cs.addQuery('sys_id', comp);
(function executeRule(current, previous /*null when async*/ ) {
var comp= current.request_item.configuration_item;
var cs= new GlideRecord('u_cmdb_ci_computersystem');
cs.addQuery('sys_id', comp); // if comp value is sys_id then apply the query on column sys_id instead of name
cs.query();
while (cs.next()) {
cs.setValue('install_status', 'Return');
cs.update();
}
})(current, previous);
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 01:21 PM
After while loops, I have added logs for cs, and it's giving me the correct system name.
But in the logs before while loop,
gs.log(cs + comp + 'TEST'); it's returning [object GlideRecord] sys_id TEST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 01:36 PM
gs.log(cs + comp + 'TEST'); it's returning [object GlideRecord] sys_id TEST
The above line is giving the sys_id value ? if yes then check if this sys_id belongs a record in table [ u_cmdb_ci_computersystem]
Share the screenshot of BR condition "When to run" tab and script part with log output.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution