8,849
edits
Changes
Savefunc
,no edit summary
{{JavaScript Syntax}}You can use '''savefunc''' to create a custom [[Browser Script]] that runs whenever a record is saved user clicks '''Save''', '''Save Draft''' or submitted'''Submit'''.
'''Instructions:'''
* Create a [[Custom Field]] on the page of type: [[Custom Field Type: Special – Browser Script]]
* Include a function in the [[Browser Script]] called '''savefunc''' that includes the [[JavaScript]] you wish to execute when the record is either saved or submitted.
* The function must return either a value of '''true''' if the record should be saved/submitted; or '''false''' if the record should not be saved/submitted.
* Standard and Custom Field validation is performed '''after''' this script is run, provided that the function has returned '''true'''. If the function returns '''false''' no further validation is performed and the record is <u>not</u> saved/submitted.
'''Example1:''' function savefunc(frm){ ''do this'' ''RunAnotherFunction()'' ''do that'' return true } * Note that [[JavaScript]] is case sensitive. '''Example 2:'''* The following sample [[JavaScript]] function will prompt the [[User|user]] to confirm if they really want to save the record.
<pre>
function savefunc(frm){do var answer = confirm ("Do you really want to save this?") if (answer){RunAnotherFunction alert ("Consider it done")do that return true }else{ alert ("Keep filling it in then") return Truefalse }
}
</pre>
* ''The "return false" isn't strictly necessary. If the function does not return true then false is assumed.''
===See Also===
* [[sbfunc]]
* [[onloadfunc]]
[[Category:JavaScript]][[Category:Validation]]