{"id":6,"date":"2026-08-08T18:44:04","date_gmt":"2026-08-08T18:44:04","guid":{"rendered":"http:\/\/corpolearn.wp\/snow\/\/business-rules-vs-client-scripts-servicenow-developer-guide\/"},"modified":"2026-08-08T18:44:04","modified_gmt":"2026-08-08T18:44:04","slug":"business-rules-vs-client-scripts-servicenow-developer-guide","status":"publish","type":"post","link":"https:\/\/corpolearn.com\/snow\/business-rules-vs-client-scripts-servicenow-developer-guide\/","title":{"rendered":"Business Rules vs Client Scripts in ServiceNow: Complete Developer Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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 <strong>Business Rules<\/strong> (Server-side) and <strong>Client Scripts<\/strong> (Browser-side), complete with performance considerations and production code templates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Server-Side: Business Rules<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Display Business Rule: Pass data to client via g_scratchpad\n(function executeRule(current, previous \/*null when async*\/) {\n    if (current.caller_id &amp;&amp; current.caller_id.vip == true) {\n        g_scratchpad.isCallerVIP = true;\n        g_scratchpad.callerDepartment = current.caller_id.department.getDisplayValue();\n    }\n})(current, previous);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. Client-Side: Client Scripts &amp; GlideAjax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Client Scripts execute inside the user\u2019s web browser (UI). Common types include <code>onLoad<\/code>, <code>onChange<\/code>, <code>onSubmit<\/code>, and <code>onCellEdit<\/code>. To fetch server data dynamically without locking the browser, always use asynchronous <strong>GlideAjax<\/strong> calls.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function onChange(control, oldValue, newValue, isLoading, isTemplate) {\n    if (isLoading || newValue === \"\") return;\n    \n    var ga = new GlideAjax(\"UserUtilsAjax\");\n    ga.addParam(\"sysparm_name\", \"getUserDetails\");\n    ga.addParam(\"sysparm_user_id\", newValue);\n    ga.getXMLAnswer(function(response) {\n        var data = JSON.parse(response);\n        g_form.setValue(\"location\", data.location);\n    });\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_cl_workflow_state":"","_cl_content_brief":"","_cl_target_topic":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-servicenow-scripting"],"_links":{"self":[{"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":0,"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corpolearn.com\/snow\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}