Populate variables from sys user table based on 'Requested for'

rin1
Kilo Guru

Hi all,

Iam working on a catalog item. The requirement is to autopopulate 6 fields (Fname, Lname, Title, Department, Email,Phone,) based on Requested For field.

In the catalog item variables, I have set the default value for all the 6 variables like below, so when the form loads all these 6 fields are populated. So no issues on that part.

javascript:(gs.getUser().getRecord().getValue("first_name"));

javascript:(gs.getUser().getRecord().getValue("last_name"));

javascript:(gs.getUser().getRecord().getValue("title")); .......etc

 

If the 'requested_for' value is changed then all these values should be populated based on the user data. I have written an onchange client script but that doesnt seems working. Below is the script. Any guidance would be much appreciated.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var gr = g_form.getReference('requested_for', getUser);
}
function getUser(gr){
    
    g_form.setValue('dccr_forename', gr.first_name);
    g_form.setValue('dccr_surname', gr.last_name);
    g_form.setValue('dccr_work_email', gr.email);
    g_form.setValue('dccr_jobtitle', gr.title);
    g_form.setValue('dccr_service_dpt', gr.department);

g_form.setValue('dccr_contact_number', gr.phone);

}

 

Thanks,

Rini

 

11 REPLIES 11

Jaspal Singh
Mega Patron
Mega Patron

Hi Rini,

Script seems to be fine. None of field is getting set with above script or there are few but few fields are not set?

Hi Jaspal,

None of the field is getting updated.  It stays with the caller details, and not getting updated with the 'Requested for' User.

 

Thanks,

Rini

As a suggestion can you try below.

1. Pass default value for requested_for only & not for other variables

2. Create an onLoad() script with code same as above instead of using default values for other variables.

Hi Jaspal,

I have removed the default value from other variables and created an onLoad script but the fields are still not populating for Requested For fields, Any thoughts?

Thanks,

Rini