PDI Project

DeIvory Gordon
Tera Guru

I am working on a project on my PDI in which I had to create an application that allows users to borrow vehicles from my company.  I have to create a business rule on Vehicle Servicing tickets that stops users from closing the tickets when the Vehicle Status is "In Service"; and display a message "You are unable to close this ticket because the Vehicle Status is In Service."

 

I am not sure how to set the condition to stop users from closing the Vehicle Servicing ticket when the vehicle status is "in Service".  I believe there are ways to do this other than a business rule, but I am required to use a business rule.  Thank you for your help, please answer plainly.

2 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @DeIvory Gordon 

 

You can create a UI policy and in policy action, mention the alert and abort action or Business rule also work, 

 

https://www.servicenow.com/community/developer-forum/business-rule-for-incident-state-change-to-reso...

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

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

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@DeIvory Gordon Apart from the business rule, you may choose to create an onSubmit client script and check if the Vehicle status is In-Service, you can show an alert message or an error message if the check returns true. The script should return false to stop the form submission in this case. 

 

Here is an example.

function onSubmit() {
   if(g_form.getValue('vehicle_state') ==8&&g_form.getValue('state')==3 ){ //assuming 8 here represents In-Service state and 3 represents closed state
       
       g_form.addErrorMessage('Vehicle is in serice ticket can\'t be closed.');
       return false;
   }
}

 

Hope this helps.

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @DeIvory Gordon 

 

You can create a UI policy and in policy action, mention the alert and abort action or Business rule also work, 

 

https://www.servicenow.com/community/developer-forum/business-rule-for-incident-state-change-to-reso...

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

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

Sandeep Rajput
Tera Patron
Tera Patron

@DeIvory Gordon Apart from the business rule, you may choose to create an onSubmit client script and check if the Vehicle status is In-Service, you can show an alert message or an error message if the check returns true. The script should return false to stop the form submission in this case. 

 

Here is an example.

function onSubmit() {
   if(g_form.getValue('vehicle_state') ==8&&g_form.getValue('state')==3 ){ //assuming 8 here represents In-Service state and 3 represents closed state
       
       g_form.addErrorMessage('Vehicle is in serice ticket can\'t be closed.');
       return false;
   }
}

 

Hope this helps.

Melan8edMermaid
Tera Contributor

Hey @DeIvory Gordon I'm stuck on this same Business rule in Sprint 3 currently.  Would you be able to help me brainstorm through my script?

 

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

// Add your code here
var currentStatus = new GlideRecord('x_1118167_lva_vehicle_servicing'); // Creates GlideRecord on the servicing table
currentStatus.addQuery('ticket_status', 'open'); // Query current ticket status
currentStatus.addQuery('vehicle_status', 'in_service'); // Query current vehicle status
currentStatus.query(); // Execute the query
if (!currentStatus.next()){ // An if statement that checks and if no match is found for the conditions of the query, it moves on with the script
gs.addErrorMessage('You are unable to close this ticket because the Vehicle Status is In Service.');
current.ticket_status = previous.ticket_status; // Revert the state change
current.setAbortAction(true);
}

})(current, previous);