How to relate multiple change request records to a single RITM?

ArpitaVK
Tera Expert

Hello

Currently, in the related list of RITM, related change records are displayed. When I open the change the records, the corresponding RITM should be displayed in the change record's related list. For that, I have configured a BR:

Table: change_request

When to run: after insert, update

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var parentSysId = current.parent;

    var ritmRec = new GlideRecord('sc_req_item');

    ritmRec.get(parentSysId);

    ritmRec.parent = current.sys_id;

    ritmRec.update();

})(current, previous);
 
What is happening is, the corresponding RITM is shown only on the latest change record added in the related list of RITM. If we open previously added change records in the related list of RITM, even though the parent is populated with that RITM number, the RITM record is not present in its related list. 
One of solutions that was suggested for this is to create M2M relationship. But can it be created for existing related list instead of adding a new related list?
1 ACCEPTED SOLUTION

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ArpitaVK 

 

What is happening is, the corresponding RITM is shown only on the latest change record added in the related list of RITM. If we open previously added change records in the related list of RITM, even though the parent is populated with that RITM number, the RITM record is not present in its related list. 
Atul: This is what expected behaviour and by design, bcz it is  1-1 table not parent and child relationship.
One of solutions that was suggested for this is to create M2M relationship. But can it be created for existing related list instead of adding a new related list?
Atul: I recommend create new M2M table and with new list, so that it will not impact the upgrades.
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

9 REPLIES 9

Harish KM
Kilo Patron
Kilo Patron

Hi @ArpitaVK updated your script:

var parentSysId = current.parent;

var ritmRec = new GlideRecord('sc_req_item');

ritmRec.addQuery('sys_id',parentSysId );

ritm.query();

//for multiple ritm do a while loop to get all records matching parent sysid

while(ritm.next())

{

ritmRec.parent = current.sys_id;

ritmRec.update();

}

Regards
Harish

Hello @Harish KM 

I updated the script, but now no any change record has RITM in its related list. I even added the logs to check upto which line the code is running; not a single log is recorded.

Hi @ArpitaVK how are you creating change from RITM? which field on change holds ritm syssid?

Regards
Harish

Hi @Harish KM 
I am creating change on RITM using either of the following two ways:

1. creating new change request record from the related list

2. editing the change request related list (slushbucket)

 

And 'Parent' field on the change request record holds the number of RITM.