How to auto populate group manager name in group owner field on selecting group name in catalog form

Pranay Verma
Tera Contributor

I want to auto populate group manager name in group manager field from sys_user_group table on selecting group in catalog form.

1 ACCEPTED SOLUTION

Mohan raj
Mega Sage

Hi @Pranay Verma,

 

If group manager variable is reference field then you will get manager name in the reference field

if you are using string field then need to use  Glide Ajax. Send the sysid to the script include, query the tables and return all the display values.

 

Try this below code 

 

Client script:

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

   //Type appropriate comment here, and begin script below
	var ga = new GlideAjax('groupManager');
	ga.addParam('sysparm_name','getManagerName');
	ga.addParam('sysparm_manager',g_form.getValue('group'));
	ga.getXML(callBackFn);
	
	function callBackFn(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		g_form.setValue('group_manager',answer);
	}
   
}

 

script include:

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

	getManagerName : function(){
		var group_id = this.getParameter('sysparm_manager');
		var group = new GlideRecord('sys_user_group');
		if(group.get(group_id)){
			return group.manager.name;
		}
		
	},

    type: 'groupManager'
});

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

Mohan.

View solution in original post

4 REPLIES 4

Mohan raj
Mega Sage

Hi @Pranay Verma,

 

Try to use on change client script 

on change variable : group 

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

   //Type appropriate comment here, and begin script below
	var manager = g_form.getReference('group').manager;
	g_form.setValue('group_manager',manager );
   
}

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

Mohan.

@Pranay Verma 

 

 write below code in  reference qualifier of your Group manager field 

 

javascript:current.variables.group.manager;

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

 

 

We are getting the sysid of the manager but not the manager name.

 

 
 
 

 

Mohan raj
Mega Sage

Hi @Pranay Verma,

 

If group manager variable is reference field then you will get manager name in the reference field

if you are using string field then need to use  Glide Ajax. Send the sysid to the script include, query the tables and return all the display values.

 

Try this below code 

 

Client script:

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

   //Type appropriate comment here, and begin script below
	var ga = new GlideAjax('groupManager');
	ga.addParam('sysparm_name','getManagerName');
	ga.addParam('sysparm_manager',g_form.getValue('group'));
	ga.getXML(callBackFn);
	
	function callBackFn(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		g_form.setValue('group_manager',answer);
	}
   
}

 

script include:

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

	getManagerName : function(){
		var group_id = this.getParameter('sysparm_manager');
		var group = new GlideRecord('sys_user_group');
		if(group.get(group_id)){
			return group.manager.name;
		}
		
	},

    type: 'groupManager'
});

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

Mohan.