Can't get user table field in custom application

Mahmood Ahmad
Tera Contributor

Hello, i have created custom scoped application in which i have field employee number, i want to auto populate this employee number from user (sys_user) table, but i can't do this. i have created client script but it didn't work.

function onLoad() {
 
   var currentUser = new GlideRecord('sys_user');
   currentUser.addQuery('sys_id', g_user.userID);
   currentUser.query();
   while (currentUser.next()){
   
    g_form.setValue('employee_number', currentUser.employee_number);
   }
   }
1 ACCEPTED SOLUTION

Hi @Mahmood Ahmad ,

 

In this case you can do  g_user.userID to get the user ID of user and then you can do glideAjax call to get the employee number and return in your script include.

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.

To call GlideAjax from Client script you can use below link.

https://docs.servicenow.com/bundle/rome-application-development/page/app-store/dev_portal/API_refere...

 


Thanks
Vijay Balotia

 

View solution in original post

3 REPLIES 3

Vijay Balotia1
Tera Guru

Hi @Mahmood Ahmad,

 

in client script you don't have to use glide record query you can simple use g_user objects.

 

function onLoad() {   
    g_form.setValue('employee_number', g_user.employee_number); 
   }

 

For more info on g_user object can refer below link

https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_script...

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks
Vijay Balotia

i have tried to show employee number in info message, but its showing empty message. i think this is scoped and global issue.
 g_form.addInfoMessage( g_user.employee_number);

Hi @Mahmood Ahmad ,

 

In this case you can do  g_user.userID to get the user ID of user and then you can do glideAjax call to get the employee number and return in your script include.

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.

To call GlideAjax from Client script you can use below link.

https://docs.servicenow.com/bundle/rome-application-development/page/app-store/dev_portal/API_refere...

 


Thanks
Vijay Balotia