- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 06:55 AM
Hello experts,
I created a business rule that creates automatically a “change request” from RITM.
Then I created another business rule that does the following : when the change request state changes to “assess” , the related RITM updates to “work in progress” : the problem is my script is not working : when I update a chg request, the related RITM didn't get updated ! I tried to fix it with chatgpt but it didn't work :
(function executeRule(current) {
if (current.state == 3) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.parent);
ritm.query();
if (ritm.next()) {
ritm.state = 2;
ritm.update();
} else {
gs.error('RITM not found ' + current.sys_id);
}
}
})(current);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:25 AM - edited 03-19-2025 08:30 AM
Hi @yasserbouat
add this code :
chg.parent = current.sys_id;
after - chg.priority = current.variables.v_priority.toString();
Then try to test it and check it parent field on change request form is updated or no.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:54 AM
This is what I found : what shoul I do next in order to make the script functionning please ?
<order/>
<outside_maintenance_schedule>false</outside_maintenance_schedule>
<parent/>
<phase>requested</phase>
<phase_state>open</phase_state>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:05 AM
So this means, when RITM creates change request, the RITM number is not updated in the parent field in the change request table. Can you share your 1st BR code? How are you establishing that the relation between change request and RITM? How do you know which RITM created which change request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:14 AM
@Dhana3 here is thescript of the first BR that creates "chg" from RITM :
(function executeRule(current) {
var chg = new GlideRecord('change_request');
chg.initialize();
chg.type = current.variables.v_model.toString();
chg.category = current.variables.v_category.toString();
chg.short_description = current.variables.v_short_description.toString();
chg.priority = current.variables.v_priority.toString();
// Ensure service reference is valid
if (current.variables.v_service) {
chg.cmdb_ci = current.variables.v_service;
}
chg.state = 1; // Optional: Defaults to "New"
// Assign to "ITSM Engineering" group
var group = new GlideRecord('sys_user_group');
if (group.get('name', 'ITSM Engineering')) {
chg.assignment_group = group.sys_id;
} else {
gs.error('Assignment group "ITSM Engineering" not found.');
}
var chgSysId = chg.insert();
if (chgSysId) {
gs.info('Change Request ' + chgSysId + ' created from RITM ' + current.sys_id);
} else {
gs.error('Failed to create Change Request from RITM ' + current.sys_id);
}
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:21 AM
Hi @yasserbouat
In this script you need to below line of code to establish a relationship between RITM and Change. There is no relationship that is why parent is showing blank in your XML.
chg.parent = current.sys_id; //
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:03 AM
Hi @yasserbouat ,
Please accept the solution as well, so that it will help future readers as well.
Regards,
Rohit