bardakov
Tera Expert
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var gr = new GlideRecord('sys_user_grmember');
	gr.addQuery('group', newValue);
	gr.query();
	if (gr.next()) {
		g_form.setValue('assigned_to', gr.user);
	}
	
	if (newValue == '') {
		g_form.clearValue('assigned_to');
	}
	
}

 

Try this

 

wc99
Tera Contributor

Hi Viktor, thanks for your script, it managed to populate the group member in "Assigned to" field once select the "assignment group". However, if clear the "assignment group" field, the "assigned to" value is not clear.

Please advise thanks in advance.  

you may try like,

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

if (newValue != ''){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', newValue);
gr.query();
if (gr.next())
g_form.setValue('assigned_to', gr.user);
}else if (newValue == '') {
g_form.clearValue('assigned_to');
}

}

View solution in original post

Try this

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

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', newValue);
gr.query();
if (gr.next()) {
g_form.setValue('assigned_to', gr.user);
}

if (newValue == '') {
alert(newValue);
g_form.setValue('assigned_to', '');
}

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

This works perfect, thank you Shishir!