auto populate user's detail on catalog item

Deepika Gangra1
Tera Expert

Hi All,

I need to populate user's details on catalog item of logged in user as well as when requested for changes.

fields are - requested for, email, phone, manager, manager phone, manager email.

 

Note: I have added default values in variable for logged in user details.

 

Thanks in advance

1 ACCEPTED SOLUTION

 

Client script

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

    //Type appropriate comment here, and begin script below
        var reqFor = g_form.getValue('requested_for');//replace with your variable backend value
	var ajax = new GlideAjax('insert_ur_script_include_name_here');
	ajax.addParam('sysparm_name','getUserData');
	ajax.addParam('sysparm_userData', reqFor );
	ajax.getXML(calBck);
	
	function calBck(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
                var userObj = JSON.parse(answer);
		g_form.setValue('field_name1',userObj.propertynameofemail);//email var backend val
                g_form.setValue('field_name2',userObj.propertynameofphone);/phone var backend val
//u can add more variables & access via their property names
	}
}

 

Script Include: Make sure to check the client callable checkbox

 

getUserData: function() {
		var userId = this.getParameter('sysparm_userData');
	        var grUser = new GlideRecord('sys_user');
                grUser.get(userId);
		var 	uObj = {
				"propertynameofemail" : grUser.getValue('email'),
				"propertynameofphone" : grUser.getValue('phone'),
	//add other entries similarly
		}
		return JSON.stringify(uObj);
	},

 

Let me know if this helps!

Thanks,

Nikita Kale

 

 

View solution in original post

19 REPLIES 19

DeepikaGangra1_1-1678885349405.png

 

Your function should start at line 19 not after type. Could you paste the entire script include code here..I'll show.

Hi Nikita this works..

but manager's phone and email are not populating through this.

Hi Deepika 

Replace the lines
grUser.getValue('manager.email') with grUser.manager.email.toString()
grUser.getValue('manager.mobile_phone') with grUser.manager.mobile_phone.toString()

It should work then.

 

Please mark the response as helpful/correct, if it answers your question.

Thanks
Nikita Kale

Thank you so much this works