As noted in the UI, a word of warning,
The correct functioning of custom Drools code introduced here is the responsibility of the author.
Custom code will be ignored by IriusRisk's migration system, which could lead to errors after upgrading your IriusRisk instance.
It is possible to force priority of answers inside a questionnaire.
There are sometimes where we may want to force which order items in a questionnaire are displayed. We can already set the priority that questions appear with the priority field in the rules editor:
By default, we cannot set the priority of specific answers in the drop down. These get sorted alphabetically. This can be an issue where some people may want their most used or most important assets at the top for example.
Below shows how these 3 answers would automatically be sorted:
We can get around this by using the drools engine to set a priority.
As of 21/12/22 there is a current lack of constructors which include the priority field. This is noted to be fixed in the future. For now, we must use the .setPriority(x) function to get around this where x is a number.
We have to create a new object and then use the .setPriority() function.
The priority number is set where 1 is highest priority and the priority descends the higher the number goes. For instance, priority 1 gets displayed before priority 2 etc.
Step 1 - Create a custom library/Risk Pattern/Countermeasures
Please follow this article/video to create a custom library, along with the custom content needed in a custom library (risk pattern, countermeasure, threats etc) in IriusRisk:
Step 2 – Create a questionnaire and answers:
To apply custom rules for setting the priority of answers in a questionnaire we need to have a questionnaire already. Please following the article below:
Step 3 – Edit the drools for the rule:
Navigate to the rules tab at the top of your screen:
Select your custom library you created in step 1 (whatever you named it):
Navigate to drools:
Find your rule for inserting your answers (whatever you named it):
On the right hand side of our screen there should be a content section, inside this will be some code. We can ignore most of this apart from the ‘then’ to ‘end’. This is the action which takes place based on the logic we outlined in step 2.
Using the above example, if we wanted to set answer B to be displayed at the top of the list we can change this in the drools rules engine as shown below:
QuestionFact ansB = new QuestionFact($group, "B", "B-Answer", "");
QuestionFact ansA = new QuestionFact($group, "A", "A-Answer", "");
QuestionFact ansC = new QuestionFact($group, "C", "C-Answer", "");
For each answer we have manually set the priority and then inserted this into the questionnaire.
We can check this worked either on project creation or if we already have a project, by choosing ‘iriusrisk’ > ’architecture questionnaire’ in the diagram.
Below is the updated answers in the questionnaire, with B being assigned the highest priority:
As we can see this has successfully applied the priority to the answers. Additional drools information can be found at: