Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

petercawdron
Kilo Guru

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

Version history
Last update:
‎09-03-2019 09:23 PM
Updated by: