Related list question

Cirrus
Kilo Sage

Hi,

On a demand form we have a related list called Affected Cost Centre where users can select one or more cost centres associated with the demand record. There is now a requirement to have the primary cost centre as a field on the demand record, so we have created a new reference field. Is there a way to relate the two, such that if the user selects  CC123 in the new field, CC123 is automatically added to the related list?

Thanks

1 ACCEPTED SOLUTION

AndersBGS
Tera Patron
Tera Patron

Hi @Cirrus ,

 

yep, you can create a scripted async / after business rule running on the demand form. So whenever the new reference field is not empty (e.g. filed with CC123), then read the field and populate it to the related list. I have done the exact same thing with a custom configuration item field in the incident form. 

 

It is off course depended on how you related list is created, which table it refers to etc. etc...

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders  

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

7 REPLIES 7

The script was wrong as I suspected The following async on insert resolved:

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

    var gr = new GlideRecord('task_cost_center');
    gr.initialize();
    gr.cost_center = current.u_cost_code;
    gr.task = current.sys_id;  
    gr.insert();
}

   )(current, previous);

Hi @Cirrus ,

 

Create you got it resolved - otherwise please see below solution:

 

I created the reference field u_cost_code in my PDI:

AndersBGS_0-1700818669754.png

Created the relationships between dmn_demand and task_cost_center:

 

AndersBGS_3-1700819634833.png

And created the business rule to updated the related list whenever the cost code is not empty:

 

 

 

(function executeRule(current, previous /*null when async*/) {
    // get the current demand costcenter
    var costCenter = current.u_cost_code;
    if (costCenter != '') {
        var cost = new GlideRecord('task_cost_center');
        cost.initialize();
        cost.task = current.sys_id;
        cost.cost_center = current.u_cost_code;
        cost.insert();
        gs.addInfoMessage('Cost center ' + current.u_cost_code + ' has been added to affected cost centers');
    }
})(current, previous);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders  

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Anil Lande
Kilo Patron

Hi,

It is not possible with OOB related list.

Please check below link to set filter condition on OOB related list.

https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/use/using-forms/task/t_Cre...

 

Or another way is to create custom relationship and add the filter criteria to show record as per your requirement.

https://www.servicenow.com/community/now-platform-articles/how-to-create-scripted-relationships-or-d...

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande