Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Query in client script?

russellprice
Tera Contributor

Hi

I have an onchange client script which auto fills fields depending on the person who is logged in and what catergerys are seleceted:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

	if (g_form.getValue('u_subcategory') == 'New' && g_form.getValue('u_category') == 'Certificate') {
		g_form.setValue('u_requested_by',g_user.userID) ;
		g_form.setValue('short_description','New Certificate Request');
		g_form.setValue('description','Certificate name:\r\nCertificate Type (SSL, SSL with EV, Wildcard, Code signing):\r\nCertificate Term:\r\nServer Software:\r\nRegion if applicable (EMEA, ASPAC,US etc)\n\n');
	}

I have got it to fill in a field depending on the user (g_user.userID) but I would also like it to fill in the users manager. I dont beleive I can use g_user for this and have to query the sys_user table? I am new to scripting and im not sure how I would encorperate a query into this script.

Any suggestions would be much appreciated.

23 REPLIES 23

Naveen4
Kilo Guru

Hi,

 

hope this helps you in getting the user manager.

find_real_file.png

VigneshMC
Mega Sage

Best way is to use glideajax for calling a script include and get value for manager. Below thread will be helpful

https://community.servicenow.com/community?id=community_question&sys_id=df864b25db1cdbc01dcaf3231f961904&view_source=searchResult

You can also try using display business rule to put the manager value in scratchpad and access the value in client script 

Thanks

Thats great, thanks.

Im very new to this so not done anything with script includes before. When I click 'client callable' it populates the script with this:

var getman = Class.create();
getman.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    type: 'getman'
});

Im not 100% sure what these means? do I just start coding on the thrid line?

EDIT: Also, in the example you provided they are trying to get the managers email, how do i get the managers name? is it somthing like gr.manager?

For your question what it means, you can go through below link.

https://community.servicenow.com/community?id=community_question&sys_id=35500fa1db98dbc01dcaf3231f961909

 

You can create at line 3 and return the value to client script

var getman= Class.create();
getman.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
getManager: function(){
	
	var id = this.getParameter('sysparm_id'); //get user_id passed from client script
var user = new GlideRecord('sys_user');
    user.get('user_name',id);
	if (user){
		return user.sys_id;// returns manager's sys_id
	}
	

},

    type: 'getman'
});