Email and requested by Autopopulate on catalog item

priya17
Tera Contributor

Hi Experts,

 

 I am working on one catalog item, in that 1. Requested By 2. Requested For  Email address  these are two variables, for these type is reference and reference table is sys_user . 

 1. Requested By for this I am using default value --- javascript:gs.getUser().getRecord().getValue('email'); 

this should be working fine, in the same way 2. Requested For  Email address is also autopapulated ( shanthi priya kakarla Email I'D ) , for this I am using script include Please help me on this requirement. 

 

script include.

var forIctuser = Class.create();
forIctuser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData: function() {

 

//get parameter

var usr = this.getParameter('sysparm_usr');

gs.info(usr + ' | ' + 'CSKCheck');

var usrDataObject = {};

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', usr);

gr.query();

if (gr.next()) {

//get backend names of fields from table or custom table

usrDataObject["eMail"] = gr.email.toString(); // if field type is reference use "getDisplayValue();" instead "toString();"

}

gs.info('MSK:' + usrDataObject["eMail"]);

var json = new JSON();

return json.encode(usrDataObject);},
type: 'forIctuser'
});

 

Catalog Client Script:

function onLoad() {
//Type appropriate comment here, and begin script below

var abc = g_form.getValue('requested_by');

//alert('abcvalue:' +abc);

var ga = new GlideAjax('forIctuser');

ga.addParam('sysparm_name', 'getUserData');

ga.addParam('sysparm_usr', abc);

ga.getXML(processResponse);

}

function processResponse(response) {

var answer = response.responseXML.documentElement.getAttribute('answer');

//alert(answer);

if (answer != '') {

var ret = JSON.parse(answer);

// use backend names of catalog item variables

g_form.setValue('requested_for_email_address', ret.eMail);

}

}

priya17_0-1671451682552.png

 

7 REPLIES 7

@ersureshbe did this worked for you?


Raghav
MVP 2023

ersureshbe
Giga Sage
Giga Sage

Hi, You can use g_user.userID and use getReference() field and achieve it. Use below script is the sample one.

 

function onChange(control, oldValue, newValue, isLoading) 
{
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function }
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.vip == 'true')
alert
('Caller is a VIP!');
}

 

Regards,
Suresh.

Balakrishna2
Tera Contributor

We have an Auto-populate section while creating a field in catalog items, there you can select the Dependent Question as a User reference field and start with the Dot walk path. In the Dot walk path, you will be able to see the fields from the user table, so that you can easily auto-populate the value without writing the script. 

 

Balakrishna2_0-1715174231040.png