Lead time calculation post risk assessment is done

Debasis Pati
Tera Guru

i have activated the risk assesment plugin and based on my questions we are calculating the risk.
Now post risk assesment is calculated i have the below requirement as well 

Normal Change (Minor) - 3 days lead time required
Normal Change (Major) - 7 days lead time required

like if the risk is low it should have the lead of minimum 3 days and it the risk is high then lead time should minimum 7 days.acoordingly .

How i should achieve this?

@Ankur Bawiskar Can you guide here?

Regards,
Debasis





4 REPLIES 4

Abbas_5
Tera Sage
Tera Sage

Hello @Debasis Pati,

 

To implement the lead time requirement based on risk assessment, you can leverage the Risk Assessment plugin in ServiceNow and configure a business rule to automatically adjust the lead time of change requests based on the calculated risk level. 
Implementation Steps:
  1. 1. Configure the Risk Assessment Plugin:
    Ensure the Risk Assessment plugin is properly set up and the risk calculation process is working correctly.
  2. 2. Create a Business Rule:
    • Condition: Trigger the business rule when a change request is created or updated and the risk level is determined.
    • Script: 
        // Get the change request risk level        var riskLevel = current.risk.getDisplayValue();        // Determine the lead time based on the risk level        var leadTime = 3; // Default lead time        if (riskLevel == "High") {            leadTime = 7; // Set lead time to 7 days for high risk        }        // Update the change request with the new lead time        current.variables.lead_time.setValue(leadTime); // Replace 'lead_time' with the appropriate field
  1. Test and Validate: Thoroughly test the business rule to ensure it correctly updates the lead time based on the calculated risk level. 
Additional Considerations:
  • Custom Fields:
    You may need to create custom fields (e.g., lead_time) on the change request form to store the calculated lead time. 
     
  • User Interface:
    Update the change request form to display the lead time to users. 
     
  • Business Logic:
    You can further customize the business rule to handle different risk levels and lead times. 
     
  • Integration with other systems:
    If the change management process integrates with other systems, ensure the lead time is updated in those systems as well. 
     
    If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in future it will be helpful to them.
     
    Thanks & Regards,
    Abbas Shaik

Hey Abbas,

How ideally people do it?

for example i am creating one normal change i have the risk assessment plugin already activated i have created one change of normal type where i have given the start date as tomorrow.
when i clicked on risk assesment depending upon my questions and values now it did set the risk value to high and as per my requirement now my change should say me lead time should be changed to proceed further because for high rish changes lead time should be 7 days how ideally this kind of scenarios are developed?

Hello @Abbas_5  & @Dr Atul G- LNG ,

so what i did for it is below

i have created a before update business rule with condition as risk changes>

Business rule:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
   
if(current.risk=='2'){
var today = new GlideDateTime();
   
    // Calculate the minimum valid date (7 days after today)
    var futureDate = new GlideDateTime();
    futureDate.addDays(7);

    // Get the start date from the record
    var startDate = new GlideDateTime(current.start_date);

    // Debugging logs
   

    // Check if the start date is less than 7 days from today
    if (startDate.getValue() < futureDate.getValue()) {
       
        gs.addInfoMessage("Start date must be at least 7 days from today as per the risk."+futureDate.getValue());
         current.setValue('start_date',futureDate.getValue());
         if(current.end_date < futureDate.getValue()){
            gs.addInfoMessage("Since the modified start date must be earlier than the end date, the end date has been removed. Please check the adjusted start date and enter a future date.");
            current.setValue('end_date','');
         }
    }
    }

    if((current.risk=='3') ||(current.risk=='4')){
var today = new GlideDateTime();
   
    // Calculate the minimum valid date (7 days after today)
    var futureDate1 = new GlideDateTime();
    futureDate1.addDays(3);

    // Get the start date from the record
    var startDate = new GlideDateTime(current.start_date);

    // Debugging logs
   

    // Check if the start date is less than 7 days from today
    if (startDate.getValue() < futureDate1.getValue()) {
       
        gs.addInfoMessage("Start date must be at least 3 days from today as per the risk."+futureDate1.getValue());
        current.setValue('start_date',futureDate1.getValue());
        if(current.end_date < futureDate1.getValue()){
            gs.addInfoMessage("Since the modified start date must be earlier than the end date, the end date has been removed. Please check the adjusted start date and enter a future date.");
            current.setValue('end_date','');
         }
    }
    }

})(current, previous);


also i have created one on change client script as well on start date .

on change client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   // Get the risk field value
   var riskValue = g_form.getValue('risk');

   // Define the minimum lead time
   if (riskValue === '2'){
      minLeadTimeDays = 7;
   }
   var minLeadTimeDays = 7; // Default lead time for high risk
   if ((riskValue === '3') || (riskValue === '4')){
      minLeadTimeDays = 3; // Lower lead time for low risk
   }

   // Get today's date
   var today = new Date();
   var minStartDate = new Date();
   minStartDate.setDate(today.getDate() + minLeadTimeDays);

   // Convert newValue (user-selected start date) to Date object
   var startDate = new Date(newValue);

   // Validate the start date
   if (startDate < minStartDate) {
      g_form.showErrorBox('start_date', 'Start date must be at least ' + minLeadTimeDays + ' days from today based on risk level.');

      // Prevent infinite loop by only setting the value when necessary
      var formattedMinStartDate = minStartDate.toISOString().split('T')[0];
      if (newValue !== formattedMinStartDate) {
         g_form.setValue('start_date', formattedMinStartDate);
      }
   }
}


Is this a correct approach?


Regards,
Debasis








Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Debasis Pati 

 

Greetings!!

 

Did you check the out-of-the-box (OOTB) risk conditions? There is also a risk condition to check the lead time.

 

DrAtulGLNG_0-1749187588949.png

 

*************************************************************************************************************
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]

****************************************************************************************************************