Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Giving alert pop up for the first save only

chaitanya_k333
Kilo Explorer


Hello All, I have given an alert message to a form. When I fill the form and click on Save button an alert gets generated. For this. I have written a simple client script. The code is

 

 

function onSubmit() {

    alert('" Are you sure you want to save this record ? You will not be able to change The Type after Save/ Submit."');

   

}

This is working accordingly when i Click on save button and saving it for the first time. Now the problem is occuring when I am doing any changes in the same form again and clicking save button, the same pop up is appearing again and again. How can I modify it like only for the first save, the alert should get triggered not when I am modifying the form again and clicking on save button. Please suggest

17 REPLIES 17

hiranmayee1
Kilo Explorer

Create a field on the form which will count how many times Save button is clicked.


Then when first time,save button is clicked the field value exceeds to 1 ,then execute script.



Thanks,


Hiranmayee


sumeet_n
Mega Guru

Use g_form.isNewRecord() in if condition. More information in below link.



GlideForm (g form) - ServiceNow Wiki


Harish Murikina
Tera Guru

Hi Chaitanya,



                    Create on display business rule and store the operation;


g_scratchpad.operation_type   = current.operatiopn();



In onsubmit script.



function onSubmit() {


if(g_scratchpad.operation_type == 'insert');


{


    alert('" Are you sure you want to save this record ? You will not be able to change The Type after Save/ Submit."');


  }


else


{


continue;


}


}



Regards,


Harish.


jsi
Giga Guru

yes. first save and insert are one and the same.so insert BR would work in this case.