Auto populate info on catalog item form

Balaji Ramanath
Kilo Contributor

Hi,

I am a newbie to catalog item form configuration and the below areas holding me to complete the form. 

1. Variable set - Reporting User Email/(would like to auto populate based on reporting user name from user table) - I have given the default value for 'Reporting User Email' as 'javascript:gs.getUser().getRecord().getValue('email');' but it still shows empty on the form. 

2. Variables - Affected User Name / Affected User Department - would like to auto-populate the user department info from the user table upon selecting the 'Affected user name'. 

Thanks. 

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you want to auto-populate default value when form loads based on logged in user then you need to use default value

If you wish to populate something on change then you would require onChange client script

What's your requirement?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Balaji Ramanath
Kilo Contributor

Hi Ankur,

Below is the Onchange script used to populate Reporting user info.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('global.IncidentRecordProducerUtil');
    ga.addParam('sysparm_name', 'getUserdata');
    ga.addParam('sysparm_user', newValue);
    ga.getXML(GetUserDetail);

    function GetUserDetail(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var details = answer.split('|');
        g_form.setValue('department', details[0]);
        g_form.setValue('email', details[1]);
		
    }

}

 

Can help on the onchange script to populate 'Affected User Department' info up on selecting the Affected user name? As I mentioned the Affected User Department is a separate variable created. So should we write a separate script for that one?

Thanks

Hi,

onChange is written on which variable?

Can you share client script configuration screenshot and how the form looks

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

Just a correction here. 

Attached is the screenshot 'Default variable' to auto-populate the default value when form loads based on the logged-in user. Note that [Reporting user name/dept/email has been created as variable sets.

Attached is the form screenshot and need help in populating the affected user department info upon selecting the Affected user name which is created as variables in the form.