How to know if related list is not empty and automatically update the field on the parent form

ss123
Tera Contributor

Hi! 

We have a requirement where we want to query the related list in Table_1 and if there' at least one record in Related_List_1, the Select Box field value will be changed in Table_1 form

 

Sample Details:

table_1 = is the current form

relate_list_1 = is the related list on the Table_1

Type = is the select box field (Choices: One , Two)

 

Scenario:

If the related_list_1 has at least 1 record in table_1 form, the Select box = 'One'

 

Thank you in Advance!

13 REPLIES 13

Hi @ss123 ,

When I check the board card related list then it has 'board' as a reference field which refers to the vbt board table.

Modified script as :-

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

var vtbcard = new GlideRecord('vtb_card');
vtbcard.addQuery('board', current.sys_id);
vtbcard.query();
if (vtbcard.next()) {
current.setValue('u_choice_2', 'no');

} else {
current.setValue('u_choice_2', 'yes');
}
})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar 

I used the modified script you provided, and still not working .. 

Both records ( created from module / created from vtb)  " u_choice_2"  value is "Yes"

Hi @ss123 ,

Share me your snapshot of When to Run tab of BR. also at the time of insertion is there any task automatically assigned to VTB record ?


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar 

 

Here's the screenshot. Also, there's no task automatically assigned to VTB record when created.

SabrinaSalazar_0-1668581939354.png

 

Hi @ss123 ,

Okay, I got confused with tables and fields. Writedown above BR on 'vbt_card' table

GunjanKiratkar_0-1668583887132.png

 

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

    var vtbtask = new GlideRecord('vtb_task');
    vtbtask.addQuery('sys_id', current.task);
    vtbtask.query();
    if (vtbtask.next()) {
        vtbtask.setValue('u_choice_2', 'no');

    } else {
        vtbtask.setValue('u_choice_2', 'yes');
    }
    vtbtask.update();
})(current, previous);

 

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy