QC for ServiceNow allows you to easily create your own code checks through the use of regular expressions (RegEx). The default quality profiles used in QC for ServiceNow will work for most projects, but you can easily tune them to fully match your needs.
Examples of adding your own rules can vary from using naming conventions for functions or variables to doing specific checks when calling some functions which perform external calls to other systems.
Each added rule can be fully configured. Once can decide into which ServiceNow element we want to do the check against, the area of impact which the check belongs to (security, upgradeability, performance, maintainability, upgradeability, scalability), its severity (high, medium, low, warning, info) and if we want to detect the line where the issue is.
Here below two rules, one for a JS check and another one for a ServiceNow best practice.
<?xml version=”1.0″ encoding=”UTF-8″?>
<BestPractices>
<BestPractice>
<Code>BUSINESS_RULES_WITH_INEFFICIENT_LOOPS</Code>
<Description>200.- Business Rules with inefficient JavaScript Loops
</Description>
<AppliesTo>Business Rule</AppliesTo>
<Severity>HIGH</Severity>
<AreaOfImpact>PERFORMANCE</AreaOfImpact>
<ResolutionTime>10</ResolutionTime>
<DocumentationLink>https://www.w3.org/wiki/JavaScript_best_practices#Optimize_loops
</DocumentationLink>
<DetectLines>true</DetectLines>
<Condition>
<ContitionType>RegexMatches</ContitionType>
<FieldName>script</FieldName>
<Regex><![CDATA[for\s*\(.*=[0-9]*;.*.length.*;.*\)]]></Regex>
</Condition>
</BestPractice>
<BestPractice>
<Code>BUSINESS_RULES_WITH_UPDATES_ON_BEFORE</Code>
<Description>30.- OnBefore Business Rules updating records on current
tables</Description>
<AppliesTo>Business Rule</AppliesTo>
<Severity>HIGH</Severity>
<AreaOfImpact>PERFORMANCE</AreaOfImpact>
<ResolutionTime>15</ResolutionTime>
<DocumentationLink>http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices#gsc.tab=0
</DocumentationLink>
<Condition>
<ContitionType>CompositeCondition</ContitionType>
<LeftCondition>
<ContitionType>AttributeEquals</ContitionType>
<FieldName>when</FieldName>
<FieldValue>before</FieldValue>
</LeftCondition>
<Operator>AND</Operator>
<RightCondition>
<ContitionType>RegexMatches</ContitionType>
<FieldName>script</FieldName>
<Regex><![CDATA[currentupdate\s*\(]]></Regex>
</RightCondition>
</Condition>
</BestPractice>
</BestPractices>
Once your regular expression is ready, Quality Clouds will check it and include it into your scans.
RegEx are available in professional and enterprise subscriptions. Find out more.
You can find more about writing regular expressions here