I am trying auto populate user location on load of a record producer . using this script but it is not populating

Rahul Singh3
Tera Contributor

I am using this script for the same :

function onLoad() {
var id = g_form.getValue('caller_id');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', id);
user.query();
if (user.next()) {
g_form.setValue('location', user.location);

}
}

Also trying to change the location is caller is changed in the same record producer and using this script.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '' || newValue == null) {
g_form.setValue('location', '');
return;
}
if (!g_form.hasField('location'))
return;
var caller = g_form.getReference('caller_id', setLocation);
}

function setLocation(caller) {
if (caller)
g_form.setValue('location', caller.location);
}

 

both are not working. could anyone suggest why?

7 REPLIES 7

Omender Singh
Tera Guru

hello

 

caller_id is a reference field , and in case you want location of caller you don't need to write any script.

 

Just by form view add callers location on form.....

 

Mark correct if you feel it servers your purpose.

 

find_real_file.png

 

 

 

 

find_real_file.png

I am trying on record producer. Thus it is not working

It's a record producer and not form

So dot walking and adding fields will not work.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader