petercawdron
Kilo Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-03-2019 09:23 PM
ServiceNow provides a simple client-side API for the GlideRecord (with an ajax callback) but it returns different objects depending on whether it is called from a regular form or the Agent Workspace.
In this example, setting the business service will set the support group from that business service as the assignment group on an incident.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//only set the business service if it is blank
if(g_form.getValue('assignment_group')==''){
var getAssignGroup = new GlideRecord('cmdb_ci_service');
getAssignGroup.addQuery('sys_id',newValue);
getAssignGroup.query(updateAssignGroup);
}
function updateAssignGroup(response){
//GlideRecord will return different objects depending on whether it is in a regular form or the Agent Workspace
if(response.hasOwnProperty('recordSet')){
g_form.setValue('assignment_group', response.recordSet[0].support_group.value, response.recordSet[0].support_group.display_value);
}else{
response.rows.forEach(function(thisRow){
thisRow.forEach(function(thisColumn){
if(thisColumn.name=='support_group'){
g_form.setValue('assignment_group', thisColumn.value);
}
});
});
}
}
}
Have fun
Labels:
- 1,602 Views
