Regarding Make fields Mandatory

Gariki Haritha
Tera Contributor

Hi Team,

 

I need to make contact name and contact number mandatory while clicking Appointment Booking button before book appointment need these two fields should be mandatory, here there is state changing and all only booking appointment. Kindly provide better approach.

 

 

Thanks and Regards

Haritha

5 REPLIES 5

AndersBGS
Tera Patron
Tera Patron

Hi @Gariki Haritha ,

 

Just make a UI Policy which make the fields mandatory based on specific condition.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Harish KM
Kilo Patron
Kilo Patron

you can make your UI Action "Appointment Booking button" as client callable and use below method to set fields mandatory

g_form.setMandatory('fieldname',true);

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

@Gariki Haritha 

on which form this is required? please share screenshots.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AnveshKumar M
Tera Sage
Tera Sage

Hi @Gariki Haritha 

Try this code in your UI Action and refer the screenshots for the UI Action configuration. 

And make sure that there are UI Poilcy or Client Script which will make the fields mandatory when state is changed. If they are not make them mandatory in the UI Action script itself using g_form.setMandatory('FIELD_NAME', true);

 

 

function bookAppointment(){
	g_form.setValue("state", "<YOUR_STATE_VALUE>");
	gsftSubmit(null, g_form.getFormElement(), 'book_appoinment_ui_action');
}

if (typeof window == 'undefined')
   updateAndRedirect();

function updateAndRedirect() {
    current.update();
    action.setRedirectURL(current);
}

 

AnveshKumarM_1-1696327172652.png

 

AnveshKumarM_0-1696327120871.png

 

Please mark my answer helpful and accept as solution if it helped 👍✔️

Thanks,
Anvesh