GlideRecord is not a constructor on client side

jonnyyan
Kilo Contributor

Hi Team,

we have a requirement that once the page load, we need to get the current user's department from sys_user table.

i just write code like below:

function onLoad() {

    //Type appropriate comment here, and begin script below

    var userID = g_user.userID;

  console.debug(userID);

    var gr = new GlideRecord('sys_user'); //   GlideRecord is not a constructor

  console.debug(gr);

  .....

}

once i debug the code, an error showing "A script has encountered an error in render events GlideRecord is not a constructor"

could you tell me how to resolve it. many many thanks

Jonny

1 ACCEPTED SOLUTION

Steven1
Tera Expert

1. As best practice you should use glide ajax or you can use use g_scratchpad to pass value from the server to the client.



1. create   a   onDisplay business rule


      - g_scratchpad.getUserDepartment = gs.getUser().getDepartmentID();



2. Create a onLoad client script.


      - g_form.setValue('department', g_scratchpad.getUserDepartment);



**untested**



Client Script Best Practices - ServiceNow Wiki


View solution in original post

4 REPLIES 4

BALAJI40
Mega Sage

Instead of that going with GlideRecord, you can go with default value.


configure the dictionary and in the default value, fill as the fallowing line of code


javascript:gs.getUser().getRecord().getDisplayValue("department");


find_real_file.png


This need to return in default value of the field and not in the onLoad client script.


go to corresponding field, configure dictionary


go to default tab and return the fallowing piece of code


javascript:gs.getUser().getRecord().getDisplayValue("department");


Steven1
Tera Expert

1. As best practice you should use glide ajax or you can use use g_scratchpad to pass value from the server to the client.



1. create   a   onDisplay business rule


      - g_scratchpad.getUserDepartment = gs.getUser().getDepartmentID();



2. Create a onLoad client script.


      - g_form.setValue('department', g_scratchpad.getUserDepartment);



**untested**



Client Script Best Practices - ServiceNow Wiki