Automated Scripted Factors - how to get multiple inputs to decide the result score

Varun Sai
Tera Contributor

Hi Team,

We have enabled the Advanced Risk and exploring the automated scripted factors. I have the below requirement and would like know why is this one not working. 

We are getting the "Impact" initially from the Risk record from the below-

I have 5 inputs as below which I need to fetch from Risk table (created custom fields on Risk table for the below and we update on the form) - 

Financial Impact,
Breadth of Impact, 
Regulatory Impact
Technology Impact
Brand Impact

 

We are calculating the Likelihood on the Risk assessment based on few questions. 

 

Inherent Risk Score is a Product of both the Impact and Likelihood. 

 

For Calculating the Impact, since we have get these from the Risk table as they are answered there. 

Amongst these 5 inputs (Financial Impact, Breadth of Impact, Regulatory Impact, Technology Impact, Brand Impact)

we need to get the highest value of the them all. 

For example let's say, below are inputs-

Financial Impact- Low (1)

Breadth of Impact - Medium (3)
Regulatory Impact - Medium (3)
Technology Impact - High (7)
Brand Impact - Low (1)
Then the Impact will be High(7).
 
In the Risk Assessment I want the Impact to show as High(7) and based on Likelihood questions, the product of Impact * Likelihood the Inherent Risk will be calculated. 
 
I don't see to get this to work as it's failing at the Impact level for which I am creating the Automated Scripted Factor.
 
 
try {
   /***Start of Custom Code. Please write your scoring formula below. */
    var grRisk = new GlideAggregate('sn_risk_risk');
    grRisk.addQuery('number', risk);   // this part I think which is not recognizing the Risk record
    grRisk.query();

    if (grRisk.next()) {
        var financialImpact = parseInt(grRisk.u_financial_impact.value) || 0;
        var breadthImpact = parseInt(grRisk.u_breadth_of_impact.value) || 0;
        var regulatoryImpact = parseInt(grRisk.u_regulatory_impact.value) || 0;
        var continuityImpact = parseInt(grRisk.u_technology_impact.value) || 0;
        var brandImpact = parseInt(grRisk.u_brand_impact.value) || 0;

     result.score = Math.max(financialImpact, brandImpact, regulatoryImpact, technologyImpact, brandImpact);  

    }

/***End of Custom Code. Do not modify anything below. */

if (isNaN(result.score)) {
    throw 'Not a number.';
} else if (result.score == Infinity) {
    throw 'Divide by zero error.';
}
} catch (ex) {
    result.error = ex;
}
 
3 REPLIES 3

Aakash2
Tera Contributor

Hi Varun, 

 

Please try by replacing 'number' with 'sys_id' in line no 4 as 'risk' variable stores sys_id of Risk record.

 

//Factor Variables -

//risk - sys_id of risk

 
  grRisk.addQuery('sys_id', risk);   // this part I think which is not recognizing the Risk record
 





 

Varun Sai
Tera Contributor

It's not working, when I change it 

ThineshT
ServiceNow Employee
ServiceNow Employee

Hi @Varun Sai ,

 

We can achieve this use case using our OOB capability available under Qualitative scoring logic field.

  1. Create 5 automated scripted factors each for Financial Impact,Breadth of Impact, Regulatory Impact,Technology Impact, Brand Impact) which will get their response from the correponding table/field.
  2. Nest them under a group factor (Impact )
  3. In the Group factor, select Qualitative scoring logic field = maximum
  4. This configuration will pick the maximum score of the impact among your 5 automated scripted factor.

 

Thanks,

Thinesh