Subject: Javascript Help
There are three problems with the code.
The first is that you created a function named confirm, which is a reserved word. You need to change the name of the function.
The second problem is that you are “returning” values…which stops the script. Get rid of the “return”s in the onSubmit and replace them with If statements.
The last problem is the most difficult to fix.
This problem is that you are testing an HTML form element, while your updated field is still on the server.
In order to test the value, the document must be refresh. You must remember that you are working with two separate entities at the same time…the Notes document and the HTML form. If you update the Notes document, you must then refresh the HTML form if you expect to access those updates using JavaScript. That is impossible with your current process because the refresh will not happen until all the code in the button completes, and that won’t happen until the document completes the full save and close process. By then it’s too late.
The solution is to place the filesave and close commands in a separate button, which is activated from the onload event.
Take the onSubmit code and put it in onLoad
Create a new button at the bottom of the form that performs a filesave and close.
Edit the html properties of this button:
Name = btn_SaveClose
Style = display=none
Hide button from Notes users. The hiding of the button on the web is done with the display=none style.
Add the line:
document.forms[0].btn_SaveClose.click()
to the onload code in an appropriate place, and that should do it.
Now, having said that I would suggest that you create a more robust method of controlling what goes on in the onLoad. For example, use a separate “control” field to tell the onload when to do things.
So first, I would change your initial button to read:
FIELD JobWorkflowState := “Pending Approval-1”;
FIELD fld_NextStepFlag := “ProcessWorkflow”
“”
That’s all you need in the button. That act of clicking a button will cause the document to refresh and the onLoad will run.
Next, I would create the save and close button as described above.
Finally, I would have in the onLoad event for the form:
var NextStep = document.forms[0].fld_NextStepFlag.value
if (NextStep != “” ) {
document.forms[0].fld_NextStepFlag.value = "" //reset fld_NextStepFlag
switch (NextStep) {
case " ProcessWorkflow ":
if (document.forms[0].JobWorkflowState.value == 'Pending Approval-1'){
if ( funcconfirm() ) {
if (validate() ) {
document.forms[0].btn_SaveClose.click()
}
}else{
validate()
}
}
break
case "SomeOtherProcess” :
break
}
}
This process will allow you to control when the onLoad performs checks via the NextStepFlag field. You can load that switch statement up with all sorts of goodies! In fact, yoiu can call buttons that execute script agents, then process the results, and call more agents without needing any user interaction. Or, use this process to breakup long LotusScript processes that call for user interaction in the middle. I find it quite useful.
Oh, and you don’t need any semi-colons at the end of JavaScript statements. The semi-colon is a statement separator, used to put two separate statements on a single line. But you DO need a colon at the end of case statements.