How to populate email ID for logged in user with Client Script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 08:00 AM - edited 01-10-2024 08:02 AM
How to populate email ID for logged in user with client script.
I need to auto populate email ID in Catalog ITEM field.
Thanks
Ashok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 08:31 AM
Hi Ashok ,
you need to write script include with on change client script to fetch the value of email id.
Please mark my answer helpful if it resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 08:41 AM
Can you please provide the script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 08:46 AM - edited 01-10-2024 08:47 AM
Hello @B Ashok ,
Create a onload client script as below:
function onLoad() {
var user = g_user.userID;
var ga = new GlideAjax('populateUserEmailAddress');
ga.addParam('sysparm_name','getaddress');
ga.addParam('sysparm_user',user);
ga.getXMLAnswer(processResponse);
function processResponse(reposnse){
alert('response is '+ reposnse ); // here you can set the value to any variable you want using g_form.setvalue()
}
}
Create a script include as below: (make sure it is client collable as per screenshot provided)
var populateUserEmailAddress = Class.create();
populateUserEmailAddress.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getaddress: function(){
var userSysId = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
gr.get(userSysId);
gs.info('email address is '+ gr.email + userSysId)
return gr.email;
},
type: 'populateUserEmailAddress'
});
See below screenshot for script include:
See below screenshot for client script:
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 07:55 AM
Does this resolved you issue ? If yes, It would be great if you mark my response as CORRECT or Helpful so that others can see this on top of the list and get benefited by this.
Thanks & Regards,
Siddhesh