Updating current record with info from Glide record

Dubz
Mega Sage

Afternoon All,

I'm on the service offering form and i want to update a reference field on here with the information contained in a reference field on the company form. I'm using a before insert business rule. What needs to happen is the support group on the service offering is set as the support group associated with a specific company when the service offering is inserted.

i've tried the below script and i've tried building up the variables but i can't seem to crack it. How do i grab that info from the company form and bring it back to my current form?

if(current.contract.vendor.name == 'Liquid UK'){

        var gr = new GlideRecord('core_company');

        gr.addQuery('name', 'Company Name i Need Info From');

        gr.query();

while(gr.next());

        current.support_group = gr.u_support_group;

}

else{

        current.support_group = current.contract.vendor.u_support_group;

}

1 ACCEPTED SOLUTION

lSurya 24
Giga Guru

Hello David,



Can you write this as on after business rule and write current.update();



if(current.contract.vendor.name == 'Liquid UK'){


        var gr = new GlideRecord('core_company');


        gr.addQuery('name', 'Company Name i Need Info From');


        gr.query();


if(gr.next());


        current.support_group = gr.u_support_group;


current.update();


}


else{


        current.support_group = current.contract.vendor.u_support_group;


current.update();


}


View solution in original post

7 REPLIES 7

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

This:



while(gr.next());


        current.support_group = gr.u_support_group;



should be:



while(gr.next())


        current.support_group = gr.u_support_group;



there's no ; after the while!


Karthik Reddy T
Kilo Sage

Hello David,



Use the   below script and try.




var gr = new GlideRecord('core_company');


        gr.addQuery('name', 'Company Name i Need Info From');


        gr.query();


while(gr.next());


        current.support_group = gr.u_support_group;


current.update():


}


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Don't do a current.update() in a before business rule. You can run into a loop.


lSurya 24
Giga Guru

Hello David,



Can you write this as on after business rule and write current.update();



if(current.contract.vendor.name == 'Liquid UK'){


        var gr = new GlideRecord('core_company');


        gr.addQuery('name', 'Company Name i Need Info From');


        gr.query();


if(gr.next());


        current.support_group = gr.u_support_group;


current.update();


}


else{


        current.support_group = current.contract.vendor.u_support_group;


current.update();


}