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

Querying the sys_user table from client script (scope app)

MKelly83
Giga Expert

Hi all

Trying to query "sys_user" table via client script. I want to retrieve the user's id and segment code based on the inputted employee's name (u_formatted_display_name)

I have written the below client script but am getting the below error message

find_real_file.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

          return;

    }

var empName = g_form.getDisplayBox('u_emp_name').value;

var gr = new GlideRecord('sys_user');

gr.addQuery('u_formatted_display_name', empName);

gr.query(myCallBack);

function myCallBack(gr) {

if(gr.next()) {

g_form.setValue('u_emp_id', gr.user_name);

g_form.setValue('u_emp_bg', gr.u_segment);

}

}

}

I can dot.walk to these fields on the form but the issue is the business wants to rename fields from whats in the sys_user table and it can't be a global change.

1 ACCEPTED SOLUTION

if they are the reference fields then you will not be able to see the user_name and emp_bg as it will always show the field value which is set for display true in sys_user table. I think these fields should be string field.


View solution in original post

13 REPLIES 13

I think it should be like,



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


          return;


    }



var employee = g_form.getReference('u_emp_name', setemployeedetails );



function setemployeedetails(employee) {


alert(employee);


g_form.setValue('u_emp_id', employee.user_name);


g_form.setValue('u_emp_bg', employee.u_segment);


}



}


thanks Shishir



this is returning



find_real_file.png


I think, that's fine, what you get with there alerts?



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


          return;


    }



var employee = g_form.getReference('u_emp_name', setemployeedetails );



function setemployeedetails(employee) {


alert(employee.user_name);


alert(employee.u_segment);


g_form.setValue('u_emp_id', employee.user_name);


g_form.setValue('u_emp_bg', employee.u_segment);


}



}


yes shishir, it is alerting the correct value now but not setting the values in fields


is u_emp_id and u_emp_bg are reference field? Can you please provide some screenshot?