onLoad Catalog Client Script - Populate Variables

Casey9
Tera Contributor

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

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

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);
    }
}

View solution in original post

7 REPLIES 7

Casey9
Tera Contributor

That did it!

Thanks very much for that, Willem!

You are very welcome! Thank you for marking the answer as correct. Can you also mark it as helpful?

Sudhanshu Talw1
Tera Guru

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