Onload client scipt does not work on service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 03:27 PM
I'm using onLoad client script to auto populate user data. It works in Native UI but not on Portal despite checking "UI type" all. Can someone help me with this?
function onLoad (control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}var user = g_form.getReference('requested_by', populateDetails);
function populateDetails(user) {
g_form.setValue('your_position', user.title);
g_form.setValue('department', user.department);
g_form.setValue('division', user.u_division);
g_form.setValue('department', user.department);
g_form.setValue('location_cbf', user.location);
g_form.setValue('building_name', user.u_building);
g_form.setValue('office_phone', user.phone);
}
}
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 05:42 PM
didn't work 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 05:47 PM
Tried it with followings and it's working fine. There's probably something different in the setting that's not mentioned in the question.
1. Variables:
2. Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requested_by', function(user) {
try {
g_form.setValue('your_position', user.title);
g_form.setValue('department', user.department);
g_form.setValue('division', user.u_division);
//g_form.setValue('department', user.department);
g_form.setValue('location_cbf', user.location);
g_form.setValue('building_name', user.u_building);
g_form.setValue('office_phone', user.phone);
} catch (e) {
alert(e.message);
}
});
}
3. Execution. I only have Department and location entries in the user table filled in.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 06:01 PM
Thomas,
I tried it by setting the default value in requested_by field and deleted the "if isLoading" check.
function onLoad() {
g_form.getReference('requested_by', function(user) {
try {
g_form.setValue('your_position', user.title);
g_form.setValue('department', user.department);
g_form.setValue('division', user.u_division);
//g_form.setValue('department', user.department);
g_form.setValue('location_cbf', user.location);
g_form.setValue('building_name', user.u_building);
g_form.setValue('office_phone', user.phone);
} catch (e) {
alert(e.message);
}
});
}
I'm now getting the fields filled in.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 07:52 PM
if its onload then your function definition is wrong , you cant have isLoading return on a onload CS
it should be just this
function onLoad() {
//Type appropriate comment here, and begin script below
}
whatever code you want to write just add in between curly braces

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 05:55 PM
Found the difference. It's because I have it onChange instead of onLoad. Tried it with onLoad and it doesn't work. It may be because "requested_by" field is not filled in.
How is the "requested_by" field is not filled in.
Maybe better to set fields using default values instead of using client script.