
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎04-29-2021 07:37 AM
Hello Everyone,
I would like to share one of my work that might helpful to my fellow ServiceNow colleagues i.e. auto populate of 'Assignment group' in 'Incident Form' for all CI's in ServiceNow CMDB. This can be extended to problem management and change management with a little bit of tweak.
For now I am taking the example of 'Incident Form', so all we need a client script like below.
Condition for Success - In my infrastructure the field in the main 'CMDB table(cmdb_ci)' the field that hold this support group information is - support_group(reference to group table),so this field(support_group) must need to have data in it's respective table(like - Windows Server table,Linux Server table,Business Service/Application Service table etc.).Now if support_group field is blank for any particular field then it will not work.
Hope this will help my fellow ServiceNow colleagues.
Take Care and Stay Safe everyone!!
- 8,183 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Just as an FYI - If you're going to use getReference(), set the value within a callback so you're not running synchronously and locking up the user form (it'll actually still do a synchronous call to get the display value).
Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('cmdb_ci' , function(response){
g_form.setValue('assignment_group' , response.support_group);
});
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Only difference is that I am using a custom field instead of support_group. Coming up UNDEFINED.
Any ideas?
function onChange(control, oldValue, newValue, isLoading)
{
if (isLoading || newValue === '')
{
return;
}
g_form.getReference('cmdb_ci', function(setSupportGroup)
{
alert(setSupportGroup.u_incident_request_group);
g_form.setValue('assignment_group', setSupportGroup.u_incident_request_group);
});
}
if I populate support_group ref field and use it, it works as expected and I would use it, but there is a lot of other things tied to the u_incident_request_group ref field.
Any thoughts?
Thx!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The suggested Client Scripts are not a bad solution if you want assignment group to be populated immediately rather than after you save the record, but be careful you are not trumping OOTB functionality.
There is OOTB functionality already in place to do what you are after. There is an OOTB business rule named "Populate Assignment Group based on CI/SO" which will populate the assignment group based on a change of either the Service Offering or the CI. This happens server side so the assignment group is populated after you save the record.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
To populate assignment group based on configuration item or service in incident, change and problem we can go with script include (client callable) then call it in onchange client script we change the CI or service that to if your CMDB table tagged with support group then you can go with this approach.
script include: -
var AssignmnetGroupCheck=Class.create();
AssignmnetGroupCheck.prototype=object.extendsobject(AbstractAjaxProcessor,{
u_getActiveGroup:function(){
var groupId='' ";
var supportGroup=newGlideRecord('cmdb_ci');
if(supportGroup.get(this.getParameter('sysparm_ci'))){
if(supportGroup.backendvalueofsupportgroup.active==true){
groupId=supportGroup.getValue('backendvalueofsupportgroup');
}
}
return groupId;
}
});
onchange client script you can choose table as incident , change and problem as per your requirement
when field changes like CI or Service
var activegroup=new GlideAjax('AssignmnetGroupCheck');
activegroup.addParam('sysparm_name', 'u_getActiveGroup');
activegroup.addParam('sysparm_ci', newValue.toString());
activegroup.addParam.getXMLAnswer(parseAnswer);
function parseAnswer(answer){
g_form.setValue('assignment_group', answer);
}
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
We can also use the below to achieve the asked
Business Rule
if(current.cmdb_ci!=previous.cmdb_ci){
var ci=new GlideRecord('cmdb_ci');
ci.addQuery('sys_id', current.cmdb_ci);
ci.query();
if(ci.next())
{
current.assignment_group=ci.assignment_group;
if(!current.assignment_group){
gs.logwarning('CI' + current.cmdb_ci + "has no assignment group")
}
}
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Team ,
I have a doubt what If however, the CI does not have a change group, then need to populate this field is with the change group that is available for service (is mandatory filed which is already selected). How we can achieve this. There is script include, on change client script on CI but also required Onload script.
Thanks