Make Justification field mandatory when change request is out of planned window

Saranya K
Tera Contributor

Hi all,

 

When Change Request moving to implement and Review State,

if Actual Start Date < Planned Start Date ,
Actual Start Date < Planned End Date,

any one of this  true then abort and throw error and make justification field mandatory and set state value to old value .

 

I have wrote the below on change of state client script . which is not working

 

SaranyaK_0-1753167261608.png

 

8 REPLIES 8

anshul_goyal
Kilo Sage

Hello @Saranya K,

Use BR instead of onChange client script, use below logic:

Trigger: On update
Condition: When State changes to "Implement" or "Review"

 

if ((current.state == '-1' || current.state == '0') &&  (current.actual_start_date < current.planned_start_date ||  current.actual_start_date < current.planned_end_date)) {

    // Abort update
    gs.addErrorMessage("Actual Start Date cannot be before Planned Start or End Date. Please justify.");

    // Make justification mandatory
    g_form.setMandatory('justification_field', true); 
    current.setAbortAction(true);  // Stops server-side update
}


Please mark my solution as Accepted and Helpful for future references.

Thanks

Hi @anshul_goyal ,

 

g_form is not a server side api

g_form is a client-side API, and Business Rules run server-side. You cannot use g_form in Business Rules. If you want to make a field mandatory dynamically, you'd need to use a Client Script or UI Policy.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Saranya K 

 

Are you not making justification mandatory at time of raising the change,if yes and value is already filled then how you can make it mandatory again? And if no, then it is not best practice while raising change you are not asking for justification. 

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

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