Submit or Insert/Insert and Stay

ao7
Tera Contributor

Hi,

I wolud like to run a script(like clearing fields) on Users form when pushing "Insert" or "Insert and Stay". However, I do not want to run it when "Submit", "Save", or any Update.

 

Is it available? Could you please advise how to do this?

2 REPLIES 2

Ravi Gaurav
Giga Sage
Giga Sage

Hey,

 

In ServiceNow, you can achieve this by creating a client script that runs on the insert event of the form, but not on the update event.

Here's an example of how you can do this:

  1. function onLoad() {
    // Get the form object
    var form = g_form;

    // Check if the form is being inserted (not updated)
    if (form.getAction() == 'insert') {
    // Clear the fields you want to clear
    form.clearValue('field1');
    form.clearValue('field2');
    // ...
    }
    }

 

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ao7 

 

What is your business case here?

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

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