- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 01:35 AM
How would i configure a script so that if the Assignment group has only one user it should auto populate the users name in assigned to field?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:27 PM
Hi MEDSNOW,
Use the below scripts as sample
Client Script: For sample , I have applied the below client script on Incident table and on change of Assignment Group field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gjax = new GlideAjax('oneName'); // name of the Script Include
gjax.addParam('sysparm_name','NameDet'); // function name of Script Include
gjax.addParam('sysparm_group',g_form.getValue('assignment_group'));
gjax.getXML(callback);
function callback(response)
{
var answ = response.responseXML.documentElement.getAttribute('answer');
g_form.addInfoMessage('Value obtnd was'+answ);
g_form.setValue('assigned_to',answ);
}
}
Script Include :
----------------------
var oneName = Class.create();
oneName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
NameDet:function(){
gs.addInfoMessage('Testing NameDet Functions');
var grp = this.getParameter('sysparm_group');
gs.addInfoMessage('Grp obtained is '+grp);
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',grp);
gr.query();
if(gr.next())
{
var k = gr.getRowCount();
gs.addInfoMessage('Inside the WHILE loop bhaiya'+k);
if(k <2)
{
gs.addInfoMessage('the user in this group is'+gr.user);
return gr.user.toString();
}}
},
type: 'oneName'
});
PLEASE mark my ANSWER as CORRECT if it served your purpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 01:52 AM
Hi ,
For achieving what you want , You need to write a Script Include in this case, using Glide Record on the table.
Return the list of users from Script include.
Write a onChange client script where using GlideAjax call the script include and get the response in which there woud be the list of users of the assignment group.
Mark this correct if it helps you.
Warm Regards,
Omkar Mone
www.DxSherpa.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 02:03 AM
Hi,
By default when you select an assignment group only group members will be listed in Assigned To field.
For your case, you can try using below sample script include. It returns sys id of the user when he/she is the only user in the selected assignment group. If there is more than one user this script returns empty value.
As Omkar mentioned you can call this from an on-Change client script.
//Script Include
var groupSysId = this.getParameter('sysparm_grpId');
var count = 0;
var userId = '';
var grpRec = new GlideRecord('sys_user_grmember');
grpRec.addQuery('group',groupSysId);
grpRec.query();
while(grpRec.next()){
count++;
if(count > 1){
break;
}
}
if(count == 1){
return userId;
}else{
return '';
}
Mark Correct if this solves your issue. Hit Like/Helpful based on the impact.
Regards,
Udhay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:27 PM
Hi MEDSNOW,
Use the below scripts as sample
Client Script: For sample , I have applied the below client script on Incident table and on change of Assignment Group field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gjax = new GlideAjax('oneName'); // name of the Script Include
gjax.addParam('sysparm_name','NameDet'); // function name of Script Include
gjax.addParam('sysparm_group',g_form.getValue('assignment_group'));
gjax.getXML(callback);
function callback(response)
{
var answ = response.responseXML.documentElement.getAttribute('answer');
g_form.addInfoMessage('Value obtnd was'+answ);
g_form.setValue('assigned_to',answ);
}
}
Script Include :
----------------------
var oneName = Class.create();
oneName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
NameDet:function(){
gs.addInfoMessage('Testing NameDet Functions');
var grp = this.getParameter('sysparm_group');
gs.addInfoMessage('Grp obtained is '+grp);
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',grp);
gr.query();
if(gr.next())
{
var k = gr.getRowCount();
gs.addInfoMessage('Inside the WHILE loop bhaiya'+k);
if(k <2)
{
gs.addInfoMessage('the user in this group is'+gr.user);
return gr.user.toString();
}}
},
type: 'oneName'
});
PLEASE mark my ANSWER as CORRECT if it served your purpose.
