Risk Assessment Business Rule to change form values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 09:56 AM
I have a Risk Assessment set up in the Change module. Based on one of the question's answer/value of service impact from the Risk Assessment, we would like to populate the Impact value on the change form. I have created a business rule that runs on insert and update:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var chg = current.task_id.getRefRecord();
chg.u_risk_assessment_complete = true;
var gr = new GlideRecord('asmt_assessment_instance_question');
gr.addQuery('source_id', chg.sys_id);
gr.addNotNullQuery('source_id');
gr.addQuery('metric', 'ee4880a1dbe9b3c0deca467239961957');
gr.query();
while(gr.next()) {
gs.log('The CHG0031870 Instance is ' +gr.instance);
gs.log('The CHG0031870 Value is ' +gr.value);
if (gr.value == 1) {
chg.impact = 0; // impact value of none
}
if (gr.value == 2) {
chg.impact = 3; // impact value of low
}
if (gr.value == 3) {
chg.impact = 2; // impact value of medium
}
if (gr.value == 4) {
chg.impact = 1; // impact value of high
}
if (gr.value == 5) {
chg.impact = 1; // impact value of high
}
}
chg.update();
})(current, previous);
Above we are taking the current assessment and pulling the sys_id of the service impact question and the value from that question. Then we have mapping to what the change form should display in the Impact field. We also mark the risk assessment as complete to trigger other logic in the background.
The problem we are encountering is that when a user makes a mistake or wants to edit the risk assessment, a new assessment instance is created. This causes the business rule to miss the logic to fire and no update occurs when the service impact question in the risk assessment is changed. The value on the change form Impact field does not automatically change to desired value. How can we get the servicenow instance to only operate off of one assessment instance per change? Or how can I alter my business rule to know which assessment instance should be looked at based on the current change request?
Thanks in advance!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 10:00 AM
Hi,
Business Rules run on the Server side and if I understand correctly, you need to display the value in the form (Client Side). I suggest to create a Client Script (On Change) and based on the conditions, you can display the impact value.
Note: If you need to execute a server code from your client script, you would need to call an Script Include from your Client Script.
Hope this helps,
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 10:54 AM
Hi Pedro,
Thank you for your reply. If I create a client-side script, how would I access the risk assessment question value in order to map to the Impact value to pre-populate the change form?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 11:01 AM
Hi,
If the risk assessment question is in your change ticket. When you create the client script, you can access to that value by using this code:
var MyRiskQuestion = g_form.getValue("< field name of your question >");
And then you can use it to make any validation or additional steps.
Hope this helps,
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 11:29 AM
The risk assessment is an assessment instance. It is a UI action that pops up the risk assessment. the question and value we need is not physically on the change form.