[{"data":1,"prerenderedAt":1248},["ShallowReactive",2],{"page-\u002Fblog\u002Fservicenow-ui-policy-vs-client-script-vs-data-policy\u002F":3,"related-\u002Fblog\u002Fservicenow-ui-policy-vs-client-script-vs-data-policy\u002F":1219},{"id":4,"title":5,"author":6,"authorUrl":7,"body":8,"date":1192,"dateUpdated":1192,"description":1193,"dqid":1192,"excerpt":1194,"extension":1195,"faq":1196,"headline":5,"meta":1209,"navigation":336,"path":1210,"seo":1211,"socialImage":1212,"stem":1213,"tags":1214,"__hash__":1218},"content\u002Fblog\u002Fservicenow-ui-policy-vs-client-script-vs-data-policy.md","ServiceNow UI Policy vs Client Script vs Data Policy: Which to Use","Gabriel Fordan","https:\u002F\u002Fsn-tricks.com\u002Fabout",{"type":9,"value":10,"toc":1182},"minimark",[11,28,31,36,191,195,206,209,243,262,378,381,385,392,415,418,515,523,531,535,542,545,565,568,720,733,737,740,761,764,825,829,836,839,1125,1128,1132,1143,1147,1170,1178],[12,13,14,15,19,20,23,24,27],"p",{},"The short answer to UI policy vs client script vs data policy in ServiceNow: use a ",[16,17,18],"strong",{},"UI policy"," to make form fields mandatory, read-only or hidden based on conditions, use a ",[16,21,22],{},"client script"," when the form needs logic a condition cannot express, and use a ",[16,25,26],{},"data policy"," when a mandatory or read-only rule must hold no matter how the record arrives. The first two only run in the browser. The third runs on the server.",[12,29,30],{},"Most mistakes come from treating the browser tools as enforcement. A mandatory field set by a UI policy stops a user on the form. It does not stop an import, a REST call or a background script.",[32,33,35],"h2",{"id":34},"the-three-tools-at-a-glance","The three tools at a glance",[37,38,39,56],"table",{},[40,41,42],"thead",{},[43,44,45,48,50,53],"tr",{},[46,47],"th",{},[46,49,18],{},[46,51,52],{},"Client script",[46,54,55],{},"Data policy",[57,58,59,73,94,108,119,130,141,153,167,179],"tbody",{},[43,60,61,65,68,70],{},[62,63,64],"td",{},"Where it runs",[62,66,67],{},"Browser",[62,69,67],{},[62,71,72],{},"Server (optionally browser too)",[43,74,75,78,84,89],{},[62,76,77],{},"Table",[62,79,80],{},[81,82,83],"code",{},"sys_ui_policy",[62,85,86],{},[81,87,88],{},"sys_script_client",[62,90,91],{},[81,92,93],{},"sys_data_policy2",[43,95,96,99,102,105],{},[62,97,98],{},"Needs code",[62,100,101],{},"No (scripts optional)",[62,103,104],{},"Yes",[62,106,107],{},"No",[43,109,110,113,115,117],{},[62,111,112],{},"Mandatory",[62,114,104],{},[62,116,104],{},[62,118,104],{},[43,120,121,124,126,128],{},[62,122,123],{},"Read-only",[62,125,104],{},[62,127,104],{},[62,129,104],{},[43,131,132,135,137,139],{},[62,133,134],{},"Visible \u002F hidden",[62,136,104],{},[62,138,104],{},[62,140,107],{},[43,142,143,146,149,151],{},[62,144,145],{},"Set values, messages, server calls",[62,147,148],{},"Only through its scripts",[62,150,104],{},[62,152,107],{},[43,154,155,158,161,164],{},[62,156,157],{},"Reverses when condition is false",[62,159,160],{},"Yes, with Reverse if false",[62,162,163],{},"Only if you code it",[62,165,166],{},"Not applicable",[43,168,169,172,174,176],{},[62,170,171],{},"Applies to import sets",[62,173,107],{},[62,175,107],{},[62,177,178],{},"Yes, if Apply to import sets is selected",[43,180,181,184,186,188],{},[62,182,183],{},"Applies to web services",[62,185,107],{},[62,187,107],{},[62,189,190],{},"SOAP, if Apply to SOAP is selected",[32,192,194],{"id":193},"ui-policies-conditional-form-behaviour-without-code","UI policies: conditional form behaviour without code",[12,196,197,198,201,202,205],{},"You find UI policies under ",[16,199,200],{},"System UI > UI Policies",", or in the UI Policies related list on a table. A UI policy has a condition and a set of ",[16,203,204],{},"UI Policy Actions",". Each action sets a field to mandatory, visible or read-only as true, false or leave alone.",[12,207,208],{},"Settings worth knowing:",[210,211,212,219,225,231,237],"ul",{},[213,214,215,218],"li",{},[16,216,217],{},"On load"," applies the policy when the form opens as well as when fields change.",[213,220,221,224],{},[16,222,223],{},"Reverse if false"," undoes the actions when the condition stops being true. Leave it selected unless you have a reason not to.",[213,226,227,230],{},[16,228,229],{},"Global"," applies the policy to every view. Clear it to target one view.",[213,232,233,236],{},[16,234,235],{},"Inherit"," applies the policy to tables that extend this one.",[213,238,239,242],{},[16,240,241],{},"Order"," decides which policy wins when two policies touch the same field. The higher order runs later and wins.",[12,244,245,246,249,250,253,254,257,258,261],{},"UI policies can also run scripts. In the Advanced view, select ",[16,247,248],{},"Run scripts"," and fill in ",[16,251,252],{},"Execute if true"," and ",[16,255,256],{},"Execute if false",". Each one is an ",[81,259,260],{},"onCondition()"," function:",[263,264,269],"pre",{"className":265,"code":266,"language":267,"meta":268,"style":268},"language-javascript shiki shiki-themes github-light github-light","\u002F\u002F Execute if true: category is \"Network\"\nfunction onCondition() {\n    g_form.showFieldMsg('cmdb_ci', 'Select the affected network device.', 'info');\n}\n\n\u002F\u002F Execute if false\nfunction onCondition() {\n    g_form.hideFieldMsg('cmdb_ci', true);\n}\n","javascript","",[81,270,271,280,295,325,331,338,344,353,373],{"__ignoreMap":268},[272,273,276],"span",{"class":274,"line":275},"line",1,[272,277,279],{"class":278},"sJ8bj","\u002F\u002F Execute if true: category is \"Network\"\n",[272,281,283,287,291],{"class":274,"line":282},2,[272,284,286],{"class":285},"sCydW","function",[272,288,290],{"class":289},"se37E"," onCondition",[272,292,294],{"class":293},"sKWpL","() {\n",[272,296,298,301,304,307,311,314,317,319,322],{"class":274,"line":297},3,[272,299,300],{"class":293},"    g_form.",[272,302,303],{"class":289},"showFieldMsg",[272,305,306],{"class":293},"(",[272,308,310],{"class":309},"sOTlB","'cmdb_ci'",[272,312,313],{"class":293},", ",[272,315,316],{"class":309},"'Select the affected network device.'",[272,318,313],{"class":293},[272,320,321],{"class":309},"'info'",[272,323,324],{"class":293},");\n",[272,326,328],{"class":274,"line":327},4,[272,329,330],{"class":293},"}\n",[272,332,334],{"class":274,"line":333},5,[272,335,337],{"emptyLinePlaceholder":336},true,"\n",[272,339,341],{"class":274,"line":340},6,[272,342,343],{"class":278},"\u002F\u002F Execute if false\n",[272,345,347,349,351],{"class":274,"line":346},7,[272,348,286],{"class":285},[272,350,290],{"class":289},[272,352,294],{"class":293},[272,354,356,358,361,363,365,367,371],{"class":274,"line":355},8,[272,357,300],{"class":293},[272,359,360],{"class":289},"hideFieldMsg",[272,362,306],{"class":293},[272,364,310],{"class":309},[272,366,313],{"class":293},[272,368,370],{"class":369},"sMN4m","true",[272,372,324],{"class":293},[272,374,376],{"class":274,"line":375},9,[272,377,330],{"class":293},[12,379,380],{},"If a UI policy needs more than a few lines of script, it is usually a client script in disguise. Move it.",[32,382,384],{"id":383},"client-scripts-logic-the-condition-builder-cannot-express","Client scripts: logic the condition builder cannot express",[12,386,387,388,391],{},"Client scripts live under ",[16,389,390],{},"System Definition > Client Scripts",". They run on load, on change of one field, on submit, or on cell edit in a list. Use them to:",[210,393,394,397,400,412],{},[213,395,396],{},"Set or clear values when another field changes",[213,398,399],{},"Show messages or ask the user to confirm",[213,401,402,403,408,409],{},"Fetch server data with ",[404,405,407],"a",{"href":406},"\u002Fblog\u002Fservicenow-glideajax-guide","GlideAjax"," or read ",[81,410,411],{},"g_scratchpad",[213,413,414],{},"Validate a value against a pattern before submit",[12,416,417],{},"A typical onChange script clears a dependent field:",[263,419,421],{"className":265,"code":420,"language":267,"meta":268,"style":268},"function onChange(control, oldValue, newValue, isLoading, isTemplate) {\n    if (isLoading || newValue === oldValue) {\n        return;\n    }\n    \u002F\u002F A new assignment group makes the old assignee meaningless\n    g_form.clearValue('assigned_to');\n}\n",[81,422,423,459,479,487,492,497,511],{"__ignoreMap":268},[272,424,425,427,430,432,436,438,441,443,446,448,451,453,456],{"class":274,"line":275},[272,426,286],{"class":285},[272,428,429],{"class":289}," onChange",[272,431,306],{"class":293},[272,433,435],{"class":434},"sj_tP","control",[272,437,313],{"class":293},[272,439,440],{"class":434},"oldValue",[272,442,313],{"class":293},[272,444,445],{"class":434},"newValue",[272,447,313],{"class":293},[272,449,450],{"class":434},"isLoading",[272,452,313],{"class":293},[272,454,455],{"class":434},"isTemplate",[272,457,458],{"class":293},") {\n",[272,460,461,464,467,470,473,476],{"class":274,"line":282},[272,462,463],{"class":285},"    if",[272,465,466],{"class":293}," (isLoading ",[272,468,469],{"class":285},"||",[272,471,472],{"class":293}," newValue ",[272,474,475],{"class":285},"===",[272,477,478],{"class":293}," oldValue) {\n",[272,480,481,484],{"class":274,"line":297},[272,482,483],{"class":285},"        return",[272,485,486],{"class":293},";\n",[272,488,489],{"class":274,"line":327},[272,490,491],{"class":293},"    }\n",[272,493,494],{"class":274,"line":333},[272,495,496],{"class":278},"    \u002F\u002F A new assignment group makes the old assignee meaningless\n",[272,498,499,501,504,506,509],{"class":274,"line":340},[272,500,300],{"class":293},[272,502,503],{"class":289},"clearValue",[272,505,306],{"class":293},[272,507,508],{"class":309},"'assigned_to'",[272,510,324],{"class":293},[272,512,513],{"class":274,"line":346},[272,514,330],{"class":293},[12,516,517,518,522],{},"This is the same pattern as the ",[404,519,521],{"href":520},"\u002Fscripts\u002Fclear-assignee-on-assignment-group-change","clear assignee on assignment group change"," script in the library. Notice it sets a value, which a UI policy action cannot do.",[12,524,525,526,530],{},"Do not use a client script to show, hide or require fields on a simple condition. You would have to write the reverse branch yourself, and the next admin will look for a UI policy first. The ",[404,527,529],{"href":528},"\u002Fblog\u002Fservicenow-client-script-best-practices","client script best practices"," guide covers the rest of the rules for writing them well.",[32,532,534],{"id":533},"data-policies-rules-that-hold-for-every-record","Data policies: rules that hold for every record",[12,536,537,538,541],{},"Data policies live under ",[16,539,540],{},"System Policy > Rules > Data Policies",". A data policy has a condition and a set of rules that make fields mandatory or read-only. When a record that breaks the policy reaches the server, the save is rejected with a data policy error.",[12,543,544],{},"The options that matter:",[210,546,547,553,559],{},[213,548,549,552],{},[16,550,551],{},"Apply to import sets"," enforces the policy on data loaded through import sets, including web service import sets.",[213,554,555,558],{},[16,556,557],{},"Apply to SOAP"," enforces it on data from SOAP web services. ServiceNow's documentation states that this option does not cover scripted SOAP services and does not affect REST. If a REST integration must respect a rule, test it on your release or back the rule with a business rule.",[213,560,561,564],{},[16,562,563],{},"Use as UI Policy on client"," also applies the policy on the form, through the UI policy engine. This gives users the same mandatory and read-only markers they would get from a UI policy, so you do not need a second, duplicate UI policy.",[12,566,567],{},"Data policies have limits. They cannot hide fields, run scripts or validate values beyond \"has a value\" and \"cannot change\". For a rule like \"planned end must be after planned start\", use a before business rule:",[263,569,571],{"className":265,"code":570,"language":267,"meta":268,"style":268},"\u002F\u002F Before business rule on change_request, insert and update\n(function executeRule(current, previous \u002F*null when async*\u002F) {\n    var start = current.getValue('start_date');\n    var end = current.getValue('end_date');\n    if (start && end && new GlideDateTime(end).before(new GlideDateTime(start))) {\n        gs.addErrorMessage('Planned end date must be after planned start date.');\n        current.setAbortAction(true);\n    }\n})(current, previous);\n",[81,572,573,578,602,626,646,682,697,711,715],{"__ignoreMap":268},[272,574,575],{"class":274,"line":275},[272,576,577],{"class":278},"\u002F\u002F Before business rule on change_request, insert and update\n",[272,579,580,582,584,587,589,592,594,597,600],{"class":274,"line":282},[272,581,306],{"class":293},[272,583,286],{"class":285},[272,585,586],{"class":289}," executeRule",[272,588,306],{"class":293},[272,590,591],{"class":434},"current",[272,593,313],{"class":293},[272,595,596],{"class":434},"previous",[272,598,599],{"class":278}," \u002F*null when async*\u002F",[272,601,458],{"class":293},[272,603,604,607,610,613,616,619,621,624],{"class":274,"line":297},[272,605,606],{"class":285},"    var",[272,608,609],{"class":293}," start ",[272,611,612],{"class":285},"=",[272,614,615],{"class":293}," current.",[272,617,618],{"class":289},"getValue",[272,620,306],{"class":293},[272,622,623],{"class":309},"'start_date'",[272,625,324],{"class":293},[272,627,628,630,633,635,637,639,641,644],{"class":274,"line":327},[272,629,606],{"class":285},[272,631,632],{"class":293}," end ",[272,634,612],{"class":285},[272,636,615],{"class":293},[272,638,618],{"class":289},[272,640,306],{"class":293},[272,642,643],{"class":309},"'end_date'",[272,645,324],{"class":293},[272,647,648,650,653,656,658,660,663,666,669,672,674,677,679],{"class":274,"line":333},[272,649,463],{"class":285},[272,651,652],{"class":293}," (start ",[272,654,655],{"class":285},"&&",[272,657,632],{"class":293},[272,659,655],{"class":285},[272,661,662],{"class":285}," new",[272,664,665],{"class":289}," GlideDateTime",[272,667,668],{"class":293},"(end).",[272,670,671],{"class":289},"before",[272,673,306],{"class":293},[272,675,676],{"class":285},"new",[272,678,665],{"class":289},[272,680,681],{"class":293},"(start))) {\n",[272,683,684,687,690,692,695],{"class":274,"line":340},[272,685,686],{"class":293},"        gs.",[272,688,689],{"class":289},"addErrorMessage",[272,691,306],{"class":293},[272,693,694],{"class":309},"'Planned end date must be after planned start date.'",[272,696,324],{"class":293},[272,698,699,702,705,707,709],{"class":274,"line":346},[272,700,701],{"class":293},"        current.",[272,703,704],{"class":289},"setAbortAction",[272,706,306],{"class":293},[272,708,370],{"class":369},[272,710,324],{"class":293},[272,712,713],{"class":274,"line":355},[272,714,491],{"class":293},[272,716,717],{"class":274,"line":375},[272,718,719],{"class":293},"})(current, previous);\n",[12,721,722,723,727,728,732],{},"The ",[404,724,726],{"href":725},"\u002Fscripts\u002Fvalidate-planned-change-dates","validate planned change dates"," script shows a fuller version, and the ",[404,729,731],{"href":730},"\u002Fblog\u002Fservicenow-business-rule-best-practices","business rule best practices"," guide explains when a before rule is the right place for this.",[32,734,736],{"id":735},"how-to-choose","How to choose",[12,738,739],{},"Ask three questions in order:",[741,742,743,749,755],"ol",{},[213,744,745,748],{},[16,746,747],{},"Must the rule hold for imports, integrations or scripts?"," Use a data policy for mandatory and read-only, or a before business rule for anything else. Add a browser tool only if users need a friendlier message on the form.",[213,750,751,754],{},[16,752,753],{},"Is it only mandatory, read-only or visible, based on field values?"," Use a UI policy.",[213,756,757,760],{},[16,758,759],{},"Does it set values, talk to the server, show messages or need real logic?"," Use a client script.",[12,762,763],{},"Some common cases:",[37,765,766,776],{},[40,767,768],{},[43,769,770,773],{},[46,771,772],{},"Requirement",[46,774,775],{},"Use",[57,777,778,786,793,801,809,817],{},[43,779,780,783],{},[62,781,782],{},"Close notes mandatory when state is Resolved, from every channel",[62,784,785],{},"Data policy with Use as UI Policy on client",[43,787,788,791],{},[62,789,790],{},"Hide the vendor fields unless category is Hardware",[62,792,18],{},[43,794,795,798],{},[62,796,797],{},"Clear the assignee when the group changes",[62,799,800],{},"Client script (onChange)",[43,802,803,806],{},[62,804,805],{},"Short description read-only after the record is created",[62,807,808],{},"Data policy, or UI policy if only the form matters",[43,810,811,814],{},[62,812,813],{},"Default the location to the caller's location",[62,815,816],{},"Client script with GlideAjax, or a server-side default",[43,818,819,822],{},[62,820,821],{},"End date must be after start date",[62,823,824],{},"Before business rule, plus an optional onChange script for instant feedback",[32,826,828],{"id":827},"conflicts-and-execution-order","Conflicts and execution order",[12,830,831,832,835],{},"When a client script and a UI policy both change the same field, the result depends on which one ran last. On load, client scripts normally run before UI policies, so the UI policy usually wins. That is not a design you should depend on. Give each field one owner: if a UI policy controls whether ",[81,833,834],{},"close_notes"," is mandatory, no client script should touch its mandatory state.",[12,837,838],{},"To find what already touches a table, run this read-only background script before adding another rule:",[263,840,842],{"className":265,"code":841,"language":267,"meta":268,"style":268},"\u002F\u002F Lists active UI policies and client scripts on a table\nvar table = 'incident';\n\nvar policy = new GlideRecord('sys_ui_policy');\npolicy.addQuery('table', table);\npolicy.addActiveQuery();\npolicy.orderBy('order');\npolicy.query();\nwhile (policy.next()) {\n    gs.info('UI policy [' + policy.getValue('order') + ']: ' + policy.getValue('short_description'));\n}\n\nvar cs = new GlideRecord('sys_script_client');\ncs.addQuery('table', table);\ncs.addActiveQuery();\ncs.query();\nwhile (cs.next()) {\n    gs.info('Client script (' + cs.getValue('type') + '): ' + cs.getValue('name'));\n}\n",[81,843,844,849,864,868,889,905,915,929,938,952,1001,1006,1011,1032,1046,1055,1064,1076,1120],{"__ignoreMap":268},[272,845,846],{"class":274,"line":275},[272,847,848],{"class":278},"\u002F\u002F Lists active UI policies and client scripts on a table\n",[272,850,851,854,857,859,862],{"class":274,"line":282},[272,852,853],{"class":285},"var",[272,855,856],{"class":293}," table ",[272,858,612],{"class":285},[272,860,861],{"class":309}," 'incident'",[272,863,486],{"class":293},[272,865,866],{"class":274,"line":297},[272,867,337],{"emptyLinePlaceholder":336},[272,869,870,872,875,877,879,882,884,887],{"class":274,"line":327},[272,871,853],{"class":285},[272,873,874],{"class":293}," policy ",[272,876,612],{"class":285},[272,878,662],{"class":285},[272,880,881],{"class":289}," GlideRecord",[272,883,306],{"class":293},[272,885,886],{"class":309},"'sys_ui_policy'",[272,888,324],{"class":293},[272,890,891,894,897,899,902],{"class":274,"line":333},[272,892,893],{"class":293},"policy.",[272,895,896],{"class":289},"addQuery",[272,898,306],{"class":293},[272,900,901],{"class":309},"'table'",[272,903,904],{"class":293},", table);\n",[272,906,907,909,912],{"class":274,"line":340},[272,908,893],{"class":293},[272,910,911],{"class":289},"addActiveQuery",[272,913,914],{"class":293},"();\n",[272,916,917,919,922,924,927],{"class":274,"line":346},[272,918,893],{"class":293},[272,920,921],{"class":289},"orderBy",[272,923,306],{"class":293},[272,925,926],{"class":309},"'order'",[272,928,324],{"class":293},[272,930,931,933,936],{"class":274,"line":355},[272,932,893],{"class":293},[272,934,935],{"class":289},"query",[272,937,914],{"class":293},[272,939,940,943,946,949],{"class":274,"line":375},[272,941,942],{"class":285},"while",[272,944,945],{"class":293}," (policy.",[272,947,948],{"class":289},"next",[272,950,951],{"class":293},"()) {\n",[272,953,955,958,961,963,966,969,972,974,976,978,981,984,987,989,991,993,995,998],{"class":274,"line":954},10,[272,956,957],{"class":293},"    gs.",[272,959,960],{"class":289},"info",[272,962,306],{"class":293},[272,964,965],{"class":309},"'UI policy ['",[272,967,968],{"class":285}," +",[272,970,971],{"class":293}," policy.",[272,973,618],{"class":289},[272,975,306],{"class":293},[272,977,926],{"class":309},[272,979,980],{"class":293},") ",[272,982,983],{"class":285},"+",[272,985,986],{"class":309}," ']: '",[272,988,968],{"class":285},[272,990,971],{"class":293},[272,992,618],{"class":289},[272,994,306],{"class":293},[272,996,997],{"class":309},"'short_description'",[272,999,1000],{"class":293},"));\n",[272,1002,1004],{"class":274,"line":1003},11,[272,1005,330],{"class":293},[272,1007,1009],{"class":274,"line":1008},12,[272,1010,337],{"emptyLinePlaceholder":336},[272,1012,1014,1016,1019,1021,1023,1025,1027,1030],{"class":274,"line":1013},13,[272,1015,853],{"class":285},[272,1017,1018],{"class":293}," cs ",[272,1020,612],{"class":285},[272,1022,662],{"class":285},[272,1024,881],{"class":289},[272,1026,306],{"class":293},[272,1028,1029],{"class":309},"'sys_script_client'",[272,1031,324],{"class":293},[272,1033,1035,1038,1040,1042,1044],{"class":274,"line":1034},14,[272,1036,1037],{"class":293},"cs.",[272,1039,896],{"class":289},[272,1041,306],{"class":293},[272,1043,901],{"class":309},[272,1045,904],{"class":293},[272,1047,1049,1051,1053],{"class":274,"line":1048},15,[272,1050,1037],{"class":293},[272,1052,911],{"class":289},[272,1054,914],{"class":293},[272,1056,1058,1060,1062],{"class":274,"line":1057},16,[272,1059,1037],{"class":293},[272,1061,935],{"class":289},[272,1063,914],{"class":293},[272,1065,1067,1069,1072,1074],{"class":274,"line":1066},17,[272,1068,942],{"class":285},[272,1070,1071],{"class":293}," (cs.",[272,1073,948],{"class":289},[272,1075,951],{"class":293},[272,1077,1079,1081,1083,1085,1088,1090,1093,1095,1097,1100,1102,1104,1107,1109,1111,1113,1115,1118],{"class":274,"line":1078},18,[272,1080,957],{"class":293},[272,1082,960],{"class":289},[272,1084,306],{"class":293},[272,1086,1087],{"class":309},"'Client script ('",[272,1089,968],{"class":285},[272,1091,1092],{"class":293}," cs.",[272,1094,618],{"class":289},[272,1096,306],{"class":293},[272,1098,1099],{"class":309},"'type'",[272,1101,980],{"class":293},[272,1103,983],{"class":285},[272,1105,1106],{"class":309}," '): '",[272,1108,968],{"class":285},[272,1110,1092],{"class":293},[272,1112,618],{"class":289},[272,1114,306],{"class":293},[272,1116,1117],{"class":309},"'name'",[272,1119,1000],{"class":293},[272,1121,1123],{"class":274,"line":1122},19,[272,1124,330],{"class":293},[12,1126,1127],{},"Check data policies for the same table in the Data Policies list before you add a UI policy that duplicates one.",[32,1129,1131],{"id":1130},"converting-between-ui-and-data-policies","Converting between UI and data policies",[12,1133,1134,1135,1138,1139,1142],{},"A UI policy form has a ",[16,1136,1137],{},"Convert this to Data Policy"," related link, and a data policy has ",[16,1140,1141],{},"Convert this to UI Policy",". Conversion is handy when a form-only rule turns out to need server enforcement. It only works cleanly for policies that use mandatory and read-only actions without scripts, because a data policy cannot carry visibility or script logic. Deactivate the original after converting, or you end up with two rules doing the same job.",[32,1144,1146],{"id":1145},"a-short-checklist","A short checklist",[210,1148,1149,1152,1155,1158,1161,1164,1167],{},[213,1150,1151],{},"Mandatory or read-only that must always hold: data policy",[213,1153,1154],{},"Same rule needed on the form: select Use as UI Policy on client instead of building a duplicate UI policy",[213,1156,1157],{},"Show, hide or require on a condition, form only: UI policy with Reverse if false",[213,1159,1160],{},"Values, messages, server calls: client script",[213,1162,1163],{},"Validation beyond \"has a value\": before business rule",[213,1165,1166],{},"One owner per field state, no overlapping rules",[213,1168,1169],{},"Test imports and integrations against the rule, not just the form",[12,1171,1172,1173,1177],{},"Get this choice right and most \"the field was mandatory but the record saved anyway\" defects disappear. Add an ",[404,1174,1176],{"href":1175},"\u002Fblog\u002Fservicenow-atf-regression-testing-best-practices","ATF test"," that inserts a record server side as well as one that uses the form, so both paths stay covered.",[1179,1180,1181],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sCydW, html code.shiki .sCydW{--shiki-default:#D73A49;--shiki-dark:#D73A49}html pre.shiki code .se37E, html code.shiki .se37E{--shiki-default:#6F42C1;--shiki-dark:#6F42C1}html pre.shiki code .sKWpL, html code.shiki .sKWpL{--shiki-default:#24292E;--shiki-dark:#24292E}html pre.shiki code .sOTlB, html code.shiki .sOTlB{--shiki-default:#032F62;--shiki-dark:#032F62}html pre.shiki code .sMN4m, html code.shiki .sMN4m{--shiki-default:#005CC5;--shiki-dark:#005CC5}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj_tP, html code.shiki .sj_tP{--shiki-default:#E36209;--shiki-dark:#E36209}",{"title":268,"searchDepth":282,"depth":282,"links":1183},[1184,1185,1186,1187,1188,1189,1190,1191],{"id":34,"depth":282,"text":35},{"id":193,"depth":282,"text":194},{"id":383,"depth":282,"text":384},{"id":533,"depth":282,"text":534},{"id":735,"depth":282,"text":736},{"id":827,"depth":282,"text":828},{"id":1130,"depth":282,"text":1131},{"id":1145,"depth":282,"text":1146},"2026-12-02","UI policy vs client script vs data policy in ServiceNow: what each one does, where it runs, and a simple rule for choosing the right one for a field.",null,"md",[1197,1200,1203,1206],{"question":1198,"answer":1199},"What is the difference between a UI policy and a data policy in ServiceNow?","A UI policy runs in the browser and controls whether form fields are mandatory, read-only or visible. A data policy runs on the server and enforces mandatory and read-only rules on the data itself, so it can also apply to import sets and SOAP web services. A UI policy can be skipped by anything that does not use the form; a data policy cannot be skipped by a form user.",{"question":1201,"answer":1202},"When should I use a client script instead of a UI policy?","Use a client script when you need logic a condition builder cannot express: setting or clearing values, showing messages, confirming with the user, or calling the server with GlideAjax. If all you need is mandatory, read-only or visible based on field values, a UI policy is simpler and reverses itself automatically.",{"question":1204,"answer":1205},"Can I convert a UI policy into a data policy?","Yes. A UI policy form has a related link to convert it to a data policy, and a data policy form has a link to convert it to a UI policy. Conversion only works when the policy fits the target's limits. A UI policy that uses scripts or controls visibility has parts a data policy cannot carry, because data policies only support mandatory and read-only.",{"question":1207,"answer":1208},"Do client scripts and UI policies run for imports and REST calls?","No. Client scripts and UI policies run in the browser on forms. Import sets, REST and SOAP calls, and server scripts never load the form, so they skip both. Enforce rules that must always hold with a data policy or a before business rule.",{},"\u002Fblog\u002Fservicenow-ui-policy-vs-client-script-vs-data-policy",{"title":5,"description":1193},"\u002Fsocial-card.png","blog\u002Fservicenow-ui-policy-vs-client-script-vs-data-policy",[1215,1216,26,1217],"ui policy","client scripts","forms","Jq_P1qgMGaJqF3V5A9VjYduK8oqqcwvPgc-U06JoMJg",[1220,1226,1241],{"path":528,"title":1221,"headline":1221,"description":1222,"date":1223,"tags":1224},"ServiceNow Client Script Best Practices: onLoad, onChange, onSubmit","ServiceNow client script best practices for onLoad, onChange and onSubmit: when to use each type, how to avoid slow forms, and safe GlideAjax patterns.","2026-11-20",[1216,1225,1217],"scripting",{"path":1227,"title":1228,"headline":1229,"description":1230,"date":1231,"tags":1232},"\u002Fblog\u002Fintroducing-servicenow-scripts-library","Introducing the ServiceNow Scripts Library: Your Go-To Resource for Ready-to-Use Code | SN-Tricks","Introducing the ServiceNow Scripts Library: Your Go-To Resource for Ready-to-Use Code","Discover the new ServiceNow Scripts Library on SN-Tricks - a searchable collection of battle-tested Client Scripts, Business Rules, and Script Includes with copy-paste functionality.","2025-11-14T10:00:00",[1233,1234,1235,1236,1237,1238,1239,1240],"ServiceNow","Scripts","Client Scripts","Business Rules","Script Includes","Development","Code Library","Best Practices",{"path":406,"title":1242,"headline":1242,"description":1243,"date":1244,"tags":1245},"ServiceNow GlideAjax: Call a Script Include from a Client Script","How to use GlideAjax in ServiceNow to call a client-callable Script Include from a client script, return JSON, and keep the call fast and secure.","2026-11-25",[1246,1216,1247,1225],"glideajax","script includes",1796173533682]