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

RaghavSh
Kilo Patron

Try below:

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

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

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', usr);

gr.query();

if (gr.next()) {

return gr.email.toString();

},

type: 'forIctuser'
});

 

Client:

 

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 != '') {

// use backend names of catalog item variables

g_form.setValue('requested_for_email_address',email);

}

}


Raghav
MVP 2023

priya17
Tera Contributor

Hi Raghav,

Thank you for your response, the Email ID is visible like a popup Msg, we need to populate in the Email field.

 

Thanks in advance 

Priya  

priya17
Tera Contributor

Hi Raghav,

 

It's comes like this.

 

priya17_0-1671458708560.png

 

  • Comment alert(answer); in your client script. This will remove the alert
  • g_form.setValue('requested_for_email_address',answer); this will set the email in your field, pls replace this in your code. 
  • Please mark the answer correct/helpful accordingly.

Raghav
MVP 2023