Calculate the Risk on Client Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 07:14 PM - edited 03-09-2025 01:51 AM
Hi,
I have a requirement to calculate the risk on on-change of client script on one of the field before record created, I have checked with code below (Calling OOTB function call, from OOTB Script Include), but this code only works after record created. i have not found any function which will work before record created
Below is the code used, I was using in Script include which is I am returning to Client Script with GlideAjax
// Check if it's a new record or existing
var RiskValue = '';
var isNewRecord = !this.getParameter('sysparm_sys_id');
var new_disruption = this.getParameter('sysparm_u_disruption');
var new_type = this.getParameter('sysparm_typ');
var new_cmdb = this.getParameter('sysparm_cmdbci');
// Create GlideRecord object
var chg = new GlideRecord('change_request');
if (isNewRecord) {
chg.initialize();
chg.setValue('type', new_type);
chg.setValue('cmdb_ci', new_cmdb);
} else {
var id = this.getParameter('sysparm_sys_id');
chg.get(id);
chg.setValue('u_disruption', new_disruption);
}
chg.setValue('u_disruption', new_disruption);
var riskCalculator = new global.RiskCalculator(chg);
riskCalculator.setDryRun(true);
riskCalculator.setHideNotification(true);
var evaluatedRiskImpact = riskCalculator.evaluateRiskImpact();
return evaluatedRiskImpact.riskCondition.risk.display_value;
@Maik Skoddow @Ankur Bawiskar Could you please guide?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2025 01:42 AM
you didn't get my query, I wanted to calculate the risk before form save. code will not work on record until save.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2025 11:10 AM
I'm not sure why you want to calculate the risk before saving. OOTB risk is set by default when it loads, so it's better to modify it there instead of changing that script
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 07:57 PM
This code is written on Script Include, Which I was calling with GlideAjax in on-Change of field disruption, if I tried same code in Background script with all value populated, this is not giving correct risk value as per criteria define for new record, same is working for exiting record.
Also would like to highlight that, if I insert record after value set in chg obj in first if condition then it gives correct Risk value.
My concern is Can we calculate the Risk Value from for new record? if yes then the method I used will help or do i needs to use other method from OOTB Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 08:04 PM
@Shaikh Mzhar
The OOTB one won’t work for new records are they aren’t created yet by the time you are calculating the risk.
You can check the OOTB script and try implementing a similar one on your client scripts based on fields from the change request form.
Downside: if you change anything within the risk formula you would need to do the same for your on-change scripts.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2025 03:17 AM
Why are you using the script? It's better to add that field as a question for risk assessment ⚖️ and assign a weight to it. The system will handle it for you!
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************