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

Hi Aman,

I was using a variable set, and now i have removed that created new variables for Requester/COmpany/Requested For and deactivated all the client scripts and script include. Just wrote a basic onload client script and fields are not populating. Its totally weird and I dunno why? Any thoughts on this?

function onLoad() {
    //Type appropriate comment here, and begin script below
    var user = g_form.getReference('dccr_requested_for', populateInfo);

    function populateInfo(user) {
        g_form.setValue('dccr_forename', user.first_name);
        g_form.setValue('dccr_surname', user.last_name);
    }
}

 

Thanks,

Rini

Okay now, its populating from backend when I give 'Try it' but it doesnt populate on the portal. Not sure why.

 

Thanks,

Rini