loio |
---|
c24569de859446819798c5dc53ac604d |
view on: demo kit nightly build | demo kit latest release
A rule consists of properties that test and advise on how possible issues can be resolved and a check function that tests the application for a specific issue. To create a rule, you need to set the properties and add a check function.
For more information on how to create rules in the user interface, see Rules Management.
You can find best practices on how to create rules in Guidelines and Best Practices .
You need to set the following properties :
Property |
Description |
---|---|
ID |
The ID of the rule. It must be a valid camelCase string consisting of between 6 and 50 alphabetic characters. |
Title |
The name of the rule in a readable format. It must be a valid string consisting of between 6 and 200 characters. |
Audiences |
Describes what audiences the rule is intended for. You can have multiple audiences selected. |
Categories |
Describes what the rule tests. You can have multiple categories selected. |
Min version |
The minimum version the rule should be checked at. Possible values are <empty string> and versions like 1.28, 1.44, etc. |
Async |
Defines if the rule check function will contain asynchronous operations. |
Description |
A short description of the rule. |
Resolution |
A short advice on what to do to fix the issue generated by the rule. |
Resolution URLs |
An array of key/value pairs of texts and URLs providing the links to documentation where the user can find how to fix the issue generated by the rule. You can have multiple resolution URLs. Key is |
Check function |
Function that checks the application against the rule. It is described in more detail in the next section. |
The check function has three main and one optional parameters. The main ones are oIssueManager
, oCoreFacade
and oScope
, and the optional one is fnResolve
. Here is more information about them:
-
oIssueManager
- allows you to add new issues with theaddIssue()
method. The issue object has the following properties:-
Severity - the possible values are:
-
sap.ui.support.Severity.Low
-
sap.ui.support.Severity.Medium
-
sap.ui.support.Severity.High
-
-
Details - free text, may include any type of details related to the issue.
-
Context - an object, which has an
ID
property. TheID
should belong to the element, which generates the issue.
-
-
oCoreFacade
- gives you access to the different elements provided by the OpenUI5 core framework: -
oScope
- retrieves elements in the scope with the following methods:-
getElements()
- returns all the elements. -
getElementsByClassName(className)
- the className can be, for example,sap.m.Button
. The function returns all elements of typesap.m.Button
. -
getPublicElements()
- returns all elements that are part of public API aggregations. -
getLoggedObjects(type)
- returns all logged objects. The method provides access to the logs and traces in the browser Console. Note that it is possible to enhance the log traces with an extrafnSupportInfo
object which you can then analyze in the rule check function. ThefnSupportInfo
function is called only when support mode is turned on with the URL parametersap-ui-support
set totrue
(sap-ui-support=true
). For more information, see Rules for the Console Traces and Logging.
Prior to version 1.54,
getElements
was not accepting any arguments and was returning all elements registered with the core. Now it accepts one query object parameter. This allows you to select only a specific subset of elements valid for your use case. The three parameters of the method aretype
,public
, andcloned
.Here is an example format:
var queryObject = { type: "sap.m.Button", // String property specifying the type to select public: true, // Boolean property specifying whether only public elements should be loaded cloned: false // Boolean argument specifying if cloned elements are needed }
When the
public
parameter is set to true, thegetElements
function only explores public aggregations. It is useful if, for example, you have a composite control comprising of public and internal subelements, and you only want to check the public ones.The
cloned
parameter allows you to filter out elements that are clones of list bindings. If you don't want to explore issues associated with multiple cloned elements, for example repeated table cell content, setcloned: false
and the results will include only one representative instance.Here is an example of a check function that checks all Input controls which are part of the public aggregation and have no parent set:
function(issueManager, oCoreFacade, oScope) { var mElements = oScope.getElements({ type: "sap.m.Input", public: true, cloned: false }); for (var n in mElements) { var oElement = mElements[n]; if (!oElement.getParent()) { issueManager.addIssue({ severity: sap.ui.support.Severity.Medium, details: "The element " + oElement.getId() + " has no parent.", context: { id: oElement.getId() } }); } } }
-
-
fnResolve
- an optional parameter. It is passed to the check function only when the rule propertyasync
is set totrue
to allow you, as the rule developer, to resolve an asynchronous operation. The rule times out if it takes more than 10 seconds to resolve.Here is an async rule code example:
function(issueManager, oCoreFacade, oScope, fnResolve) { // Some async operation setTimeout(function () { … fnResolve(); }, 2000); }
Make sure to call
issueManager.addIssue()
in your check function so that issues can be seen in the analysis results.
Related Information