Autopopulate assigned_to list based on assignment_group in Incident table using clientscript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2023 12:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 01:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 01:19 AM
Hi @MYousaf111
If you see the OOTB configuration of Assigned To , you will get any idea, Why you need this on client script
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 01:25 AM
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.
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 01:37 AM - edited ‎12-19-2023 01:39 AM
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.
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:new scriptIncludename().scriptincluefunctionnanme(current.assignment_group);
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand