GlideRecords in Client Scripts within Agent Workspace
Import
·
Sep 04, 2019
·
article
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
View original source
https://www.servicenow.com/community/now-platform-articles/gliderecords-in-client-scripts-within-agent-workspace/ta-p/2327467