Submitting the same InfoPath form multiple times to the same document library in SharePoint

November 17, 2006

Long title, eh?

My problem was to do just the above, i.e. I had to name the filled out forms with a date and time marker. Because of that, when someone changed the contents of the form, a new one was created with the same name except for the date and time, where as I wanted it to amend the existing file but keep the original name.

I noticed on Google Groups that someone had a similar problem, but the solution wasn’t explained in detail (and since I’m a newbie on InfoPath 2003, it was a little challenge).

Anyway, here’s how I did it:

1. First I needed to do this in javascript, since the default submitting options didn’t allow this behaviour. On the Tools menu, I chose Submitting Forms and then in the Submitting Forms dialog box, clicked Enable Submit. In the Submit box, I clicked Submit Using Custom Script. Also enabled Open Microsoft Script Editor, and then I clicked OK. The Microsoft Script Editor unveiled to me for the first time, with a new function called function XDocument::OnSubmitRequest(eventObj) in place.

2. I went back to the (Design) template in InfoPath and added a textbox controller at the bottom. I named it filename, set the default value to “0” (or whatever), and then went back to the script editor.

3. In the OnSubmitRequest function I added the following code to read the field value from the filename textbox, and if it is zero (which it will be the first time the form is used) a conditional statement that creates a new filename (plus it writes to the new/old file in the sharepoint forms library):


var blnSubmitSuccess = false;
var strPath = "http://servername/sites/sitename/projectname/formslibraryname/"; var strFilename = XDocument.DOM.selectSingleNode("//my:filename").text;if (strFilename == "0")
 {
  strFilename = ...  // Insert code here to generate a filename of your liking
  XDocument.DOM.selectSingleNode("//my:filename").text = strFilename;
 }
var strUrl = strPath + strFilename;

// Submit the form to the form library.

var objXmlHttp = new ActiveXObject("MSXML2.XMLHTTP.5.0");

try
{
  objXmlHttp.Open("PUT", strUrl, false);
  objXmlHttp.Send(XDocument.DOM.xml);
}
catch (e)
{
  XDocument.UI.Alert("Couldn't create file in SharePoint library due to the following error.\n\n"
  + e.number + " - " + e.description);
}

// Status codes of 200 or 201 indicate that the form
// has been submitted successfully.

if (objXmlHttp.Status == 200 || objXmlHttp.Status == 201)
{
  blnSubmitSuccess = true;
}

return blnSubmitSuccess;

That’s it! Now you can change the form all you like, but it will be saved properly and keep it’s original name.

About these ads

4 Responses to “Submitting the same InfoPath form multiple times to the same document library in SharePoint”

  1. stina Says:

    alltså, jag förstår nästan inte hur du kan tycka det är intressant. å andra sidan kan jag läsa om pixlar och nya plugins i illustrator i flera dygn i streck.
    men ändå, du är SKUM! (loves it, though)

  2. Kori Says:

    I want to submit the same form but have it given a new filename each time. How can I do that? Also, when I hit submit, I want to also send an email to someone that I choose, do you know the code for that?

  3. Microserf Says:

    Hello Kori!

    Sure, just omit the first if-clause in the code and set the strFilename to something unique, eg include a date/timestamp.

    As far as submitting the form to an e-mail address, I did just that in my form. Don’t have access to the code now, but I used the MailEnvelope object, which you can read about here:

    http://msdn2.microsoft.com/en-us/library/aa167754(office.11).aspx

    Let me know if this helped you.

  4. juan Says:

    HI,
    I experienced a similar problem, I just wanted to let you know this can be solved without Script and it is possible through the submit options in InfoPath2003.

    Check out my blog post:
    http://www.imaginets.com/cs/blogs/juanl/archive/2008/07/22/submitting-the-same-infopath-form-multiple-times-to-the-same-document-library-in-sharepoint-alternative-solution-and-timing-issues.aspx


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: