- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 08:59 AM - edited 04-24-2025 09:31 AM
Hi All
I have a variable "Change State," which is referenced to "Change" table.
When related change ticket state changes to CCB, I need to update the variable "Change State" as well on RITM.
Please suggest the feasible resolution.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 10:43 PM
what does this mean -> When related change ticket state changes to CCB, I need to update the variable "Change State" as well on RITM.
Are you saying this variable should reflect the state whenever CHG state is updated?
if yes then use after update business rule on change_request table
Ensure you form the encoded query like this and use in script and give correct variable sysId
Assumption: I assume your change state variable is string type
Condition: State Changes
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addEncodedQuery('variables.042f4f871b431a108e08fc451a4bcb97=' + current.sys_id); // give here the variable sysId which holds reference to CHG table in your catalog item
ritmRec.query();
if (ritmRec.next()) {
ritmRec.variables.changeStateVariableName = current.state.getDisplayValue(); // give here the variable name
ritmRec.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
04-24-2025 11:30 AM
Hi @Km Sh ,
Try to create one business rule
Table: change_request
When: after update
Condition: current.state == <value_for_CCB>
Script :
// Replace 'ccbStateValue' with the actual value for CCB (e.g., 4, 6, etc.)
if (current.state == 'ccbStateValue') {
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('variables.active_change_request_number', current.sys_id); // assumes variable is reference type
ritmGR.query();
while (ritmGR.next()) {
// Get the variable using its name — replace 'change_state' with your real variable name
var itemVar = new GlideRecord('sc_item_option');
itemVar.addQuery('request_item', ritmGR.sys_id);
itemVar.addQuery('item_option_new.name', 'change_state');
itemVar.query();
while (itemVar.next()) {
itemVar.value = current.state.toString(); // you could also map it to display value if needed
itemVar.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 10:43 PM
what does this mean -> When related change ticket state changes to CCB, I need to update the variable "Change State" as well on RITM.
Are you saying this variable should reflect the state whenever CHG state is updated?
if yes then use after update business rule on change_request table
Ensure you form the encoded query like this and use in script and give correct variable sysId
Assumption: I assume your change state variable is string type
Condition: State Changes
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addEncodedQuery('variables.042f4f871b431a108e08fc451a4bcb97=' + current.sys_id); // give here the variable sysId which holds reference to CHG table in your catalog item
ritmRec.query();
if (ritmRec.next()) {
ritmRec.variables.changeStateVariableName = current.state.getDisplayValue(); // give here the variable name
ritmRec.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