Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

DocClose MessageBox returns

Not applicable
I have a dynamic form that I've created with a message at the end reminding the customer to save a copy for their records. What I'm not sure how to do, is have the user go back to the form if they click cancel. Here's my code for the docclose event:



xfa.host.messageBox("Did you submit your order and save a copy for your records?",2,2)



After the message comes up, the document closes when either option is clicked. How do I get it to go back to the form with the data still filled in, so they can do the options I mentioned above? (Save/submit)
18 Replies
pguerett
Level 10
Level 10
Instead of using a message Box use an app.response where it will return what the user selected. Then you can test it with an if statement and take the appropriate action.
Not applicable
I'm still learning mode, and I'm not sure where I would put the app.response? I had the messagebox at the root in the docclose event. Would I still use the docclose? Can you give me an example of code for the app.response?
pguerett
Level 10
Level 10
var cResponse = app.response({

cQuestion: "Did you submit your order and save a copy for your records?",

cTitle: "This is the title of the box.",

cDefault: "Yes",

cLabel: "Your answer: "

});

if (cResponse != "Yes"){

//Force the user to save the doc

app.alert("Saving the document for your records!");

app.execMenuItem("SaveAs")

}
Not applicable
I tried putting that code in on a test form and it does give me the boxes that it was suppose to. But it still gives me the same situation, when I type no or click cancel, the form is still gone and I can't do anything. It also doesn't prompt to save or submit the form. I did the code in the same place, docclose. Am I just entering the code in the wrong event?
Not applicable
I tried the code on a button and I with that, was able to get the prompts to save as with the answer of "no" or by clicking cancel. But it didn't give me the option to close the form if I click ok?



Is the only way to create this code with a button? Or is there a way to give these messages when closing the document?
pguerett
Level 10
Level 10
If you put a button on your form that will do the close for you then you can control it as above. If you allow the user to File/Close then you cannot control it (as far as I know anyways).



That would be no different than hit the x at the top right of the app.



The preSave will only fire if you do a saveAs so that woudl not be a viable solution.
Not applicable
I can definitely see how that would be. Thank you for everything. That helped me out a lot. Do you happen to know how I can get the application to close under the "yes" option of the code you supplied?
Not applicable
I think I'm still missing something. I'm using this code and it won't work. Would I just use an "else" statement after the "if" statement such as:



var cResponse = app.response({

cQuestion: "Did you submit your order and save a copy for your records?",

cTitle: "This is the title of the box.",

cDefault: "Yes",

cLabel: "Your answer: "

});

if (cResponse != "Yes"){

//Force the user to save the doc

app.alert("Saving the document for your records!");

app.execMenuItem("SaveAs")



else app.execMenuItem("Close")
pguerett
Level 10
Level 10
so the else part will look like this:



} else {

app.aexecMenuItem("Close")

}



The first } closes the then portion of the if statement (it is not present in your sample code).
Not applicable
That works! Thank you! Is there a way to do the same thing, only to have a yes/no in the responsebox. I need to make this as simple as possible for the user. Maybe instead of using the OK/CANCEL have those be the yes or no clicks for the answer without an actual answer box?? (Let me know if that doesn't make an ounce of sense.)



I really want to thank you for all of your help.
pguerett
Level 10
Level 10
It makes sense ....the alert functionality will do that for you so instead of app.response you woudl replace it with this code:



app.alert({

nIcon: 2, nType: 2,

cTitle: " the title of the box",

cMsg: "The question you want to ask?"

})



Like before a value is returned ...the values are:



1: if OK is pressed

2: if Cancel is pressed

3: if No is pressed

4: if Yes is pressed



The nType controls which buttons are displayed. 2 means Yes/No

and the nIcon indicates which icon to use 2 is a question.
Not applicable
So how would I control the response? To go back to the form if Cancel(or no) is clicked or close the form if OK (or yes) is clicked. I feel like an idiot.
pguerett
Level 10
Level 10
Building on the original example the cResponse variable will hold a 1,2,3,or 4 value. In your case only 3 or 4 will appear so you can check it with an if statement and act accordingly.
Not applicable
Hi Paul,



Is there a way to remove the "Warning: JavaScript Window" from the alert?



thanks,
Allta_Media
Level 2
Level 2
You can change the titled of the dialog box; however, the "Warning:JavaScript Window" alert only be removed if the code is run from a trusted context.
Not applicable
How can this be done? Do I have to Certify the document?



Thanks.