|
| 1 | +<?xml version="1.0" encoding="UTF-8"?><record_update table="scan_linter_check"> |
| 2 | + <scan_linter_check action="INSERT_OR_UPDATE"> |
| 3 | + <active>true</active> |
| 4 | + <category>performance</category> |
| 5 | + <description>When using setValue() on a reference field, be sure to include the display value with the value (sys_id). If you set the value without the display value, ServiceNow does a synchronous Ajax call to retrieve the display value for the record you specified. This extra round trip to the server can leave you at risk of performance issues.</description> |
| 6 | + <documentation_url>https://developer.servicenow.com/dev.do#!/guides/tokyo/now-platform/tpb-guide/client_scripting_technical_best_practices</documentation_url> |
| 7 | + <finding_type>scan_finding</finding_type> |
| 8 | + <name>Using setValue()'s displayValue Parameter with Reference Fields</name> |
| 9 | + <priority>3</priority> |
| 10 | + <resolution_details>Using the third parameter, where display name of the reference record can be passed.</resolution_details> |
| 11 | + <run_condition/> |
| 12 | + <score_max>100</score_max> |
| 13 | + <score_min>0</score_min> |
| 14 | + <score_scale>1</score_scale> |
| 15 | + <script><![CDATA[(function(engine) { |
| 16 | +
|
| 17 | + engine.rootNode.visit(function(node) { |
| 18 | + if (node.getTypeName() === "STRING") { |
| 19 | + var text = node.toSource(); |
| 20 | + |
| 21 | + // looks for all occurrences of g_form.setvalue() and verifies it has all the relevant |
| 22 | + // paramters, which includes display name to avoid the synchronous ajax call |
| 23 | + var pattern = /g_form\.setValue\(([^,]*),([^,]*)\)/gm; |
| 24 | + var regExp = new RegExp(pattern); |
| 25 | + var matchFound = regExp.test(text); |
| 26 | + if (matchFound){ |
| 27 | + engine.finding.incrementWithNode(node); |
| 28 | + } |
| 29 | + } |
| 30 | + }); |
| 31 | +
|
| 32 | +})(engine);]]></script> |
| 33 | + <short_description>Using setValue()'s displayValue Parameter with Reference Fields</short_description> |
| 34 | + <sys_class_name>scan_linter_check</sys_class_name> |
| 35 | + <sys_created_by>admin</sys_created_by> |
| 36 | + <sys_created_on>2023-10-13 13:18:39</sys_created_on> |
| 37 | + <sys_id>85c352ae2f3db11002eb2ca62799b68e</sys_id> |
| 38 | + <sys_mod_count>2</sys_mod_count> |
| 39 | + <sys_name>Using setValue()'s displayValue Parameter with Reference Fields</sys_name> |
| 40 | + <sys_package display_value="Example Instance Checks" source="x_appe_exa_checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_package> |
| 41 | + <sys_policy/> |
| 42 | + <sys_scope display_value="Example Instance Checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_scope> |
| 43 | + <sys_update_name>scan_linter_check_85c352ae2f3db11002eb2ca62799b68e</sys_update_name> |
| 44 | + <sys_updated_by>admin</sys_updated_by> |
| 45 | + <sys_updated_on>2023-10-13 14:49:20</sys_updated_on> |
| 46 | + </scan_linter_check> |
| 47 | +</record_update> |
0 commit comments