g_user is not working. WHY????
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2022 04:39 AM
Hi All,
my Onload script is not working. Please help
function onLoad() {
 
var a = g_user.userID.email;
 
 alert("Result: " +a);
}
I am getting result as Undefined.
- Labels:
- 
						
							
		
			Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2022 05:11 AM
Hi 
There are limitations of using and accessing the user object. You can go with the following script if you want email of current loggedin user at client side :
Client Script : OnLoad
function onLoad() {
 //Type appropriate comment here, and begin script below
 var a = g_user.userID;
 var ga = new GlideAjax('checkCIandCC');
 ga.addParam('sysparm_name', 'getData');
 ga.addParam('sysparm_user', a);
 ga.getXML(getData);
function getData(response) {
 var answer = response.responseXML.documentElement.getAttribute("answer");
 alert(answer);
 }
}   
Script Include: Client Callable true
var checkCIandCC = Class.create();
checkCIandCC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData: function() {
var sysID = this.getParameter('sysparm_user');
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", sysID);
gr.query();
if (gr.next()) {
return gr.email;
}
},
type: 'checkCIandCC'
});
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
Please Mark My Response as Correct/Helpful based on Impact
 Regards,
Gunjan Kiratkar
2X ServiceNow MVP 
Community Rising Star 2022
Youtube : ServiceNow Guy 
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2022 07:07 AM
