- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 09:43 PM
I'm trying to write an OnLoad Client Script for a catalog item. On the form we have two reference fields to the sys_user table. One is called Requestor (u_requestor) and the other is On Behalf Of (mrb_on_behalf_of) - this field can be used if someone needs to request access for someone else.
If this field is populated I want it to populate some fields with that users details (mrb_on_behalf_of), if that field is not filled in then I want it to populate the fields with the Requestors user details (u_requestor). I've got the below script, however it's only working for the Requestors details and not the On Behalf Of. The reason I am using on load is because we're using an order guide and the same variables are on the catalog items.
function onLoad(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getReference('mrb_on_behalf_of');
if (name ==null){
userObject = g_form.getReference('u_requestor',setUserInfo);}
else {
userObject = g_form.getReference('mrb_on_behalf_of',setUserInfo);}
function setUserInfo(userObject){
g_form.setValue('division',userObject.u_division);
g_form.setValue('position_title_02',userObject.title);
g_form.setValue('department',userObject.department);
}
}
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 10:23 PM
Can you try this:
function onLoad(control, oldValue, newValue, isLoading) {
var name = g_form.getValue('mrb_on_behalf_of');
if (name) {
userObject = g_form.getReference('mrb_on_behalf_of', setUserInfo);
}
else{
userObject = g_form.getReference('u_requestor', setUserInfo);
}
function setUserInfo(userObject) {
g_form.setValue('division', userObject.u_division);
g_form.setValue('position_title_02', userObject.title);
g_form.setValue('department', userObject.department);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 09:49 PM
Try this
function onLoad() {
var userObject;
var name = g_form.getReference('mrb_on_behalf_of');
if (name ==null || name == '' ){
userObject = g_form.getReference('u_requestor',setUserInfo);}
else {
userObject = g_form.getReference('mrb_on_behalf_of',setUserInfo);}
function setUserInfo(userObject){
g_form.setValue('division',userObject.u_division);
g_form.setValue('position_title_02',userObject.title);
g_form.setValue('department',userObject.department);
}
}
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 10:11 PM
Hi Muhammad,
Thanks for the suggestion, unfortunately that didn't work. Still only populating the Requestor details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 09:53 PM
You should remove the
if (isLoading || newValue == '') {
return;
}
This is exiting the script when it is loading, something you do not want to do on an onload client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 10:23 PM
Can you try this:
function onLoad(control, oldValue, newValue, isLoading) {
var name = g_form.getValue('mrb_on_behalf_of');
if (name) {
userObject = g_form.getReference('mrb_on_behalf_of', setUserInfo);
}
else{
userObject = g_form.getReference('u_requestor', setUserInfo);
}
function setUserInfo(userObject) {
g_form.setValue('division', userObject.u_division);
g_form.setValue('position_title_02', userObject.title);
g_form.setValue('department', userObject.department);
}
}