
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 07:03 AM
Again I'm struggling with my poor developer knowhow and would appreciate some help.
I'd like to a client script on change of assigned_to that sets the assignment_group if the group is empty and the assigned_to to only belongs to ONE group with a specific group_type ...
>>> this is what I get on change of assigned_to ...
onChange script error: ReferenceError: assignment_group is not defined function onChange_incident_assigned_to_4(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } if (assignment_group == '') { var gr = new GlideRecord("sys_user_grmember"); gr.addQuery('user',assigned_to); gr.addQuery('group.type','CONTAINS', "incident"); gr.query(); if (gr.getRowCount() == '1'); assignment_group = gr.group; } }
To clarify ... a group could belong to more than one type at a time ... and if the user belongs to more than one group with the specific type - nothing should happen.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2017 04:23 AM
Final Version working now:
Script Include:
Get1GroupAjax:
Client callable true
var Get1GroupAjax = Class.create();
GetSingleGroupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignmentGroup: function() {
var assignedTo = this.getParameter('sysparm_a');
var typus = "97ff1cecdba462006b2ebc2ffe96xxx"; // incident type
var aGroup ="";
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',assignedTo);
gr.addQuery('group.type','CONTAINS', typus);
gr.query();
if (gr.getRowCount() == '1') {
gr.next();
aGroup = gr.group;
}
return aGroup;
},
type: 'Get1GroupAjax'
});
****************************
Client Script: AutoSet1Group
Table Incident
On Change of assigned_to
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if(newValue != oldValue){
var ga = new GlideAjax('Get1GroupAjax');
ga.addParam('sysparm_name', 'getAssignmentGroup');
ga.addParam('sysparm_a',g_form.getValue('assigned_to'));
ga.getXML(HelloWorldParse);
}
return;
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group',answer);
g_form.showFieldMsg('assigned_to', +answer);
}
… still if you can manage to use Assignment Rules … u should … I was not able to get them work in this case …

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 07:06 AM
this is not a good practice . try to avoid glide record in client script.
please refer the thread below
Populate assignment group based on assigned to

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 07:07 AM
Hi,
Change assignment_group to g_form.getValue('assignment_group') in line no. 5 and do not use Glide record in client script. Use glideajax instead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 07:13 AM
You can also use asynchronous GlideRecord: query(Function responseFunction

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 07:09 AM
Firstly,
the condition if(assignment_group =='') is wrong.
Write var ag = g_form.getValue('assignment_group');
if(a=='')
{
}