When developing applications on the ServiceNow platform, choosing whether to execute logic on the server or on the client browser is a fundamental architectural decision. This guide outlines the key differences between Business Rules (Server-side) and Client Scripts (Browser-side), complete with performance considerations and production code templates.
1. Server-Side: Business Rules
Business Rules execute on the ServiceNow app server when records are queried, inserted, updated, or deleted. They ensure database integrity regardless of whether a record is updated via form, REST API, or background script.
// Display Business Rule: Pass data to client via g_scratchpad
(function executeRule(current, previous /*null when async*/) {
if (current.caller_id && current.caller_id.vip == true) {
g_scratchpad.isCallerVIP = true;
g_scratchpad.callerDepartment = current.caller_id.department.getDisplayValue();
}
})(current, previous);
2. Client-Side: Client Scripts & GlideAjax
Client Scripts execute inside the userβs web browser (UI). Common types include onLoad, onChange, onSubmit, and onCellEdit. To fetch server data dynamically without locking the browser, always use asynchronous GlideAjax calls.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === "") return;
var ga = new GlideAjax("UserUtilsAjax");
ga.addParam("sysparm_name", "getUserDetails");
ga.addParam("sysparm_user_id", newValue);
ga.getXMLAnswer(function(response) {
var data = JSON.parse(response);
g_form.setValue("location", data.location);
});
}