user record producer as a directory

ServNowDev
Tera Guru

I want to use a record producer to have the user select the users name and show the field i have on the producer name phone populate the phone number to use the record producer as a directory anyone used record producers in this way here is the code im using

 

var user = current.variables.first_name;

var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', user);
gr.query();

if(gr.next()){
	current.setValue(producer.phone, gr.phone);
	current.setAbortAction();
}
producer.portal_redirect = '/sp';

 

 

 

Thomas42_0-1725551793028.png

 

1 REPLY 1

Hemanth M1
Giga Sage
Giga Sage

Hi @ServNowDev ,

 

1)Why don't you use out of the box feature(Dependent value) on the Phone variable as below to set Phone number automatically

HemanthM1_0-1725554258827.png

 

2)Use Onsubmit clien script to check if Phone varibale is empty, if  is empty throw a warning message and abort

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (!g_form.getValue("phone varibale Name")) { //replace with your phone variable value
        alert("Phone is empty")
        return false;
    }
}

 

Hope this helps!!!

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025