- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 08:29 PM
Hi, I have a requirement, after select an assignment group, one of the members from the group should auto populate. If the assignment group field clear again, the assigned to field will be cleared also. I am new to ServiceNow, and any help is appreciate, thanks!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', g_form.getValue('assignment_group'));
gr.query(function(_gr) {
if (_gr.next()) {
g_form.setValue('assignment_group', _gr.group.toString());
}
});
}
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 08:23 PM
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');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2018 12:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 08:10 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 08:23 PM
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');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 08:26 PM
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