diff --git a/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/README.md b/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/README.md new file mode 100644 index 0000000000..0eab8c5369 --- /dev/null +++ b/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/README.md @@ -0,0 +1,11 @@ +**Client script Deatils** +1. Table: sys_script +2. Type: onSubmit +3. UI Type: Desktop + +**Benefits** +1. This client script will prevent admin users to do insert/update operation in onBefore business rules. +2. It will help to avoid HealthScan findings thus increasing healthscan score. +3. Will prevent recursive calls. + +Link to ServiceNow Business Rules best Practise : https://developer.servicenow.com/dev.do#!/guide/orlando/now-platform/tpb-guide/business_rules_technical_best_practices diff --git a/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/script.js b/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/script.js new file mode 100644 index 0000000000..78fa387872 --- /dev/null +++ b/Client-Side Components/Client Scripts/Health Scan Prevent Insert Update in Before BRs/script.js @@ -0,0 +1,15 @@ +function onSubmit() { + /* + This client script will prevent insert and update operation in onBefore business rules. + Table: sys_script + Type: onSubmit + Ui Type: Desktop + */ + var whenCond = g_form.getValue('when'); // when condition of business rule + var scriptVal = g_form.getValue('script'); // script value of business rule. + + if (whenCond == 'before' && (scriptVal.indexOf('insert()') > -1 || scriptVal.indexOf('update()')) > -1) { + alert("As per ServiceNow best Practise insert and update should be avoided in onBefore BRs. If you still want tp proceed try deactivating client script : " + g_form.getUniqueValue()); + return false; + } +}