Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

DocClose MessageBox returns

Avatar

Former Community Member
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

Avatar

Former Community Member
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.

Avatar

Former Community Member
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?

Avatar

Former Community Member
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")

}

Avatar

Former Community Member
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?

Avatar

Former Community Member
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?

Avatar

Former Community Member
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.

Avatar

Former Community Member
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?

Avatar

Former Community Member
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")

Avatar

Former Community Member
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).

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
Hi Paul,



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



thanks,

Avatar

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.

Avatar

Former Community Member
How can this be done? Do I have to Certify the document?



Thanks.