- 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-10-2020 12:25 AM
That did it!
Thanks very much for that, Willem!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2020 12:36 AM
You are very welcome! Thank you for marking the answer as correct. Can you also mark it as helpful?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 10:44 PM
Hi Casey
just a tip, how we manage this:
Requested By field: readonly(using onload)
Requested For field: editable field
First of all create a onLoad script :
function onLoad() {
var user;
var name = g_form.getReference('mrb_on_behalf_of');
if (name ==null || name == '' )
{
user = g_form.getReference('u_requestor',setUserInfo);
}
else
{
user = g_form.getReference('mrb_on_behalf_of',setUser);
}
function setUser(userObject){
g_form.setValue('division',user.u_division);
g_form.setValue('position_title_02',user.title);
g_form.setValue('department',user.department);
}
}
Then create a onChange script on the Requested for field.
Thanks
Sudhanshu