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

yes, at the end of script include,it should be

if (user){
		return user.manager.toString();// returns manager's sys_id
		
	}
	

Ok, I dont even get 'null' with this one. Just a blank alert

update script include

 user.get('user_name',id);

as 

 user.get('sys_id',id);

Ahah! we now have a sysID coming up in the message box?

How do we get that converted into a name and added to a field?

field is reference or string field.

If string, then update the script include to return name

return user.manager.name.toString();

if reference, then you can set the sys_id itself