Help closing Infopath after filling a form

E

erick-flores

Hello all

I am not sure if this is a question for this NG but maybe somebody can
help me, it should be simple anyways.
I have created a form in infopath. The form is publish into a
sharepoint library. Everything is working fine, but once I fill the
form and press the submit button Infopath wont close, the form will
close but not the actual program. I have to close it after the
submition. What I want is close Infopath once I submit the form. How do
I do this?

Thank you
 
D

Deb

This is a great question that I have asked in the past as well. For the life
of me, I don't understand why that's not a standard option. Why would you
want to close the form, but leave befuddled users in InfoPath???

Anyway, when I asked this before it evolved into also needing to cofirm that
required fields had been answered and the result was this:

function SubmitButton::OnClick(eventObj)
{
if (XDocument.Errors.Count > 0)
{XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).")
return;
}
Try
{
XDocument.Submit()
}
Catch(e)
{
XDocument.UI.Alert("The form cannot be submitted.");
Application.ActiveWindow.Close(true);
}
}


The problem is that this is now giving me an error that "Try" is undefined.
I'm hoping somebody can troubleshoot this and tell me why. If they can, they
we will both have the answer we need. The above code would go in the code of
the Submit button.
 
S

S.Y.M. Wong-A-Ton

JScript is case sensitive. Use lower-case instead like in

try {}
catch (e) {}
 
D

Deb

S.Y.M:

I have changed the code to look like this:

function SubmitButton::OnClick(eventObj)
{
if (XDocument.Errors.Count > 0)
{XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).")
return;
}
try
{
XDocument.Submit()
Application.ActiveWindow.Close(true);
}
catch(e)
{
XDocument.UI.Alert("The form cannot be submitted");
}
}

It gives me the error no matter what I do. I have tested a submit with
Rules and it works fine. How do I trap that error to determine what it is?
 
S

S.Y.M. Wong-A-Ton

Are you getting the same 'Try is undefined' error or another error? It seems
odd to me that you would be getting the same error, since "Try" with a
capital T is not in the code anywhere.

The only other thing I can see wrong with your code is that you didn't end
all code lines with a semi-colon (;). Use an Alert with e.Message to view the
error message from within the catch.
 
D

Deb

I'm sorry. I don't know what you mean by e.Message. Thinking I'd guess, I
changed my XDocument.UI.Alert("The form cannot be submitted"); to
XDocument.UI.Alert(e.Message);

Now all I get is a blank dialog box, so there is being a message thrown. I
just don't know what it is.

Don't let the code here fool you. I had very little to do with it. It's
been the kind people in this forum that suggested it a few months back.
 
D

Deb

The Try message was resolved by the lowercase. Now, what's happening is it
traps the error of not providing the required fields, but when all required
fields are provided, it's processing the catch. I have tried a simple Submit
with Rules and it works fine, so I know it's not the data connection.
 
S

S.Y.M. Wong-A-Ton

And if you don't catch the error by removing the try-catch block, what is the
error that appears?
 
D

Deb

"The Form was not submitted."

Can you give me the code to change the Try-catch statement to display the
error message?

Thanks!
 
S

S.Y.M. Wong-A-Ton

Deb, there isn't any special code to catch the error message. The code you
used should have worked. 'The form was not submitted' is just an informative
message, and not an error, so you cannot really catch it. You need to figure
out why your form is not being submitted.
 
D

Deb

S.Y.M:

It's giving me that error message because that's what's being caught:

function SubmitButton::OnClick(eventObj)
{
if (XDocument.Errors.Count > 0)
{
XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).")
return;
}
try
{
XDocument.Submit()
Application.ActiveWindow.Close(true);
}
catch(e)
{
XDocument.UI.Alert("The form cannot be submitted.");
}
}

The form submits fine without this code, so it must be something in the code
itself?

Deb
 
S

S.Y.M. Wong-A-Ton

Sorry, I thought you removed the try...catch like I indicated in one of my
previous posts. I did a little bit of searching and the correct syntax for
the error is not e.Message, but e.description. So try the following:

try
{
XDocument.Submit();
Application.ActiveWindow.Close(true);
}
catch (e)
{
XDocument.UI.Alert(e.description);
}

If you are still getting an error, the problem is with the code above the
try...catch block.

if (XDocument.Errors.Count > 0)
{
XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).")
return;
}
 
D

Deb

Thank you! Now I can grab the error message which says:

"InfoPath cannot submit the form because the form template does not support
it.
The form definition (.xsf) file is missing the submit element (xsf:submit)."
 
J

Josiah Smith

I have a question along the same lines, but of a slightly different nature.

We designed our initial forms with InfoPath 2003 to submit using a comma
inbetween a patient's last name and their first name. When we moved to the
2007 beta, InfoPath would replace the comma with an underscore, no matter
what we did. We were able to work-around it, though by using JScript code to
do an http save event to basically overwrite the file in our sharepoint
library, but that was with the old Object Model. Are there any examples or
documentation for this same process using the 2007 Managed Object Model in C#?
 
D

Deb

Holy enchilada, Josiah. I hope you weren't directing that question to me.
;-) I'm just a person who has been lucky enough to get extraordinary
assistance from people on this forum, but with no real talent of my own.

Hopefully, S.Y.M is watching.
 
J

Josiah Smith

Sorry about that! I was directing it towards S.Y.M., but I guess I should
just start a new thread; this one is slightly old. I also find much more
experienced users here, and hope I didn't scare you too much!

Josiah
 
S

S.Y.M. Wong-A-Ton

You need to enable submit through Tools > Submitting Forms > Enable submit
command and buttons.
 
D

Deb

Oh, my gosh. I can't believe I was missing that fundamental step.

Thank you for your help, S.Y.M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top