The CreatorCon Call for Content is officially open! Get started here.

Clear the form field values when Reset to draft button is clicked

Sprankle
Tera Contributor

I have a requirement to clear the form field values on demand table when reset to draft is clicked ,As soon as the demand is reset to Draft they should clear to allow for the new ones created as the user works through the process.

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Sprankle 

You need to modify the UI Action code and reset the field to be empty. However, I don’t think it’s best practice—values entered by the user should be preserved. What’s your use case for making it empty? If these are mandatory fields, it could cause issues.

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

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

Is their any way to dynamically clear all the non mandatory entered field vlaues 

Hi @Sprankle 

I doubt it—maybe you need to check which fields are mandatory and which are not, and then update the Reset UI Action code accordingly. But what's the business need here for resetting the fields?

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

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Sprankle 

try this in client side UI action

I hope you are aware on how to create client side UI action.

var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.clearValue(fields[x]);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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