Custom Submission of Forms (or - how to tell which submit button was clicked)

B

blaine

Hey everyone. I will try my best to describe my problem. Bear with
me! :)

I am using a SharePoint form library with InfoPath.

I have an existing form. This form has many fields on it, and a
submit button which executes a custom JScript function I have written
to submit the form. This script uploads the form via HTTP to the
sharepoint library. It works just fine.

The problem is this. I now have to have TWO submit buttons. One that
submits the form regularly, and another button that submits the form
but also sets a variable that indicates the form is CLOSED. So one
button says 'SUBMIT FORM' and the other says 'SUBMIT AND CLOSE
FORM'.

I have created two regular buttons, not "submit" buttons, to take care
of this. When they are pushed I have them calling a custom function,
Submit_Form(), which is simply the old Submit button callback.

When you submit the form using this method, the form is uploaded just
fine to the server. The server displays it in the sharepoint form
library. However, when you attempt to open the existing form into
Infopath, Infopath says that it cannot find the necessary template
file and fails.

I am looking for one of two solutions:

1. Somehow using two submit buttons (both call the same code) but
somehow distinguishing which one is called, and acting accordingly to
set the state variable (closed or open) before uploading the form.
2. Adding the additional functionality that must be missing from my
current design. I imagine that when the 'submit' button is pushed, as
opposed to a regular button, Infopath does something to complete the
submission process.

Help would be EXTREMELY appreciated!
Thanks,
Blaine

The code is partial - there are functions missing to keep space to a
minimum.
Code:
// This is the original submit function:
function Submit_Form(eventObj)
{
// *** If the submit operation is successful, set
// * eventObj.ReturnStatus = true;
// * If the submit operation is successful, set
// *** eventObj.ReturnStatus = true.
var fSuccessful = false;
var submitNew = true;
var strUrl = buildURL();
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); // Create an
xmlhttp object.
var stage_msg = "";

//added_eng_feedback = XDocument.DOM.selectSingleNode("/
my:myFields/
my:eng_added_feedback_field").text

try
{
// See whether the document with the same name already exists
in the Windows SharePoint Services (WSS) document library.
oXmlHttp.Open("HEAD", strUrl, false);
oXmlHttp.Send();

if (oXmlHttp.Status == 200)
{
// *** The Form already exists on the file
system. Since
// * We are updating an existing form, we
must first delete it.
// * The only way this could go bad is if
there was a loss of
internet
// * in between when we delete the file and
when we upload it.
// * This also assumes that if we're able to
delete the file,
then
// * we're able to save a new file in its
place. We do it this
// *** way because you cannot overwrite a file
that already exists.
oXmlHttp.Open("DELETE", strUrl, false);
oXmlHttp.send();
submitNew = false;
}


// Issue another head command to see if the file does
not exist
oXmlHttp.Open("HEAD", strUrl, false);
oXmlHttp.Send();

// *** No document with the URL has been found. Continue to
submit.
// * If you must replace the original file, you must call
// * oXmlHttp.Open("DELETE", strUrl, false) to delete the
document
// *** in the WSS document library (which we did above)
if (oXmlHttp.Status == 404)
{
// Put the document in the WSS document library.
oXmlHttp.Open("PUT", strUrl, false);
oXmlHttp.Send(XDocument.DOM.xml);

// A 200 status code or a 201 status code indicates that
the form has been submitted successfully.
if (oXmlHttp.Status == 200 || oXmlHttp.Status == 201)
{
fSuccessful = true;
}
} else {
XDocument.UI.Alert("HTTP Error Code: " +
oXmlHttp.status + ": " +
oXmlHttp.statusText + " - You may not have permission to submit the
form");
}
}
catch (er){
// General Catch All Error Handling
XDocument.UI.Alert(oXmlHttp.Status + " " + er);
}

if (fSuccessful)
{

eventObj.ReturnStatus = true;
//SetDirty(false) = do not prompt to save as...
// We do not "save" the form since we submitted it via HTTP
above
XDocument.SetDirty(false);

} else {
XDocument.UI.Alert(oXmlHttp.Status);
XDocument.UI.Alert("There was a failure in submitting the
form.");
eventObj.ReturnStatus = false;
}
return fSuccessful;
}

//=======
// The following function handler is created by Microsoft Office
InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function TE_Submit_Form::OnClick(eventObj)
{
// The Test Engineer's Initial Request is being submitted...
Submit_Form(eventObj);
build_testlab_email()
// A small hack to close infopath
Application.Windows.Item(0).Activate();
Application.ActiveWindow.Close(true);
}
 

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