The CreatorCon Call for Content is officially open! Get started here.

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

Thanks Surya, that solution has worked for me.



Thanks to everyone else for your input as well, it's much appreciated


sbrnag
Mega Expert

Use the below code



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.hasNext()) {


        current.support_group = gr.u_support_group;


}


}


else{


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


}


vinothkumar
Tera Guru

Hi David,



I hope company is the reference field on the service offering form, so you have to pass the sys_id. If you want to still check with the name itself, use getDisplayValue() to get the name and there by add the condition as name.



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


var companyID = current.company;   // Getting company sys_id Value


        var gr = new GlideRecord('core_company');


        gr.addQuery('sys_id', companyID);


        gr.query();


        while(gr.next())


            current.support_group = gr.u_support_group;


}


else{


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


}