Email and requested by Autopopulate on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 04:22 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 04:30 AM - edited 12-19-2022 04:31 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 05:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 06:05 AM
Hi Raghav,
It's comes like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 07:10 AM
- 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