The CreatorCon Call for Content is officially open! Get started here.

Autopopulate assigned_to list based on assignment_group in Incident table using clientscript

MYousaf111
Tera Contributor

Can anyone please help how to populate the assigned to list based on assignment groups using the client script? And I need a simple code. I really appreciate any help you can provide.

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi

based on what criteria should the user selected from the assignment group?

Sorry, but this is not a "simple" topic and there are different solutions available in ServiceNow. 

And for all of them you have to implement/configure anything.

Maik

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @MYousaf111 

 

If you see the OOTB configuration of Assigned To , you will get any idea, Why you need this on client script

 

LearnNGrowAtul_0-1702977575968.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

SunilKumar_P
Giga Sage

Hi @MYousaf111, you don't need a client script for it. That Assigned to field should already be dependent on Assignment Group. Incase not, then go to the assigned_to filed dictionary and update Dependant Field as assignment_group.

 

SunilKumar_P_0-1702977873934.png

 

Regards,

Sunil

Anand Kumar P
Giga Patron

Hi @MYousaf111 ,

If your requirement is like when assignment group selected then show only users belongs to assignment group in assigned to field you can use dependent field  in assigned to dictionary entry no need client script.

AnandKumarP_0-1702978096767.png
If you want only in client script go with onchange client script and script include it will set one user

 

Onchange client script on assignment group fild:
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(){
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();

if(k <2)
{
return gr.user.toString();
}}
},
type: 'oneName'
});

 

Reference qualifier:

 

assignmentGroup: function(a){
var arryVal = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',a);
gr.query();
while(gr.next()){
arryVal.push(gr.user.toString());
}
return 'sys_idIN' + arryVal.join(',');

},

 

In assigned to field call script include like: javascript&colon;new scriptIncludename().scriptincluefunctionnanme(current.assignment_group);

Mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand