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:
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");
objXmlHttp.Open("PUT", strUrl, false);
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;
That’s it! Now you can change the form all you like, but it will be saved properly and keep it’s original name.