- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 07:54 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2017 08:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2017 03:06 AM
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");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2017 07:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 06:47 AM
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");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2017 08:23 PM
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