Updating RITM when related CHG updates

yasserbouat
Tera Guru

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 : 

yasserbouat_0-1742392102431.png

 

 

(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);

 

 

1 ACCEPTED SOLUTION

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.

View solution in original post

13 REPLIES 13

Rohit  Singh
Mega Sage

Hi @yasserbouat ,

 

You need to debug if your 2nd BR is getting triggered or not. Use Add Message to determine the same.

Also when a change Request is getting created from RITM, then in the RITM parent filed the newly created CR is getting mapped? 

 

Also make below changes in the 2nd BR

(function executeRule(current) {

    
    if (current.state == 3) {

        var ritm = new GlideRecord('sc_req_item');
        
        ritm.addQuery('parent', current.sys_id);       // Changes here
        ritm.query();

        if (ritm.next()) {
            ritm.state = 2;  
            ritm.update();
          
        } else {
            gs.error('RITM not found ' + current.sys_id); 
        }
    }

})(current);

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Dhana3
Kilo Sage

Hi @yasserbouat ,

 

Have you checked what is stored in parent field on change request table? Depending on that value you need to modify the code. There are lot of ways which you can verify your script. Use background script, add info message or add logs in your script. 

@Dhana3 thanks for your reply : but where can i find the "parent" field please ? 

yasserbouat_0-1742394771032.pngyasserbouat_1-1742394798018.png

 

Hi @yasserbouat ,

 

Click on the hamburger menu on the change form, click on show xml and search for parent there. Tell me what value it has.

Dhana3_0-1742395855713.png