Creating a new infopath document in document library using SPServices

Feb 15, 2013 at 12:29 AM
Is it possible to create an empty infopath document in a document library using SPServices?
I've uploaded an infopath template to the library. When I run the following code, it creates an entry in the library but its name and type are not set correctly. Any help would be greatly appreciated.


$().SPServices({
            operation: "UpdateListItems",
            async: false,
            batchCmd: "New",
            listName: "listname",
            valuepairs: [["DocIcon", "xml"],["LinkFilename", "test.xml"]],
            completefunc: function(xData, Status) {
                alert(String(Status));
            }
        });
});
Thanks
Feb 15, 2013 at 12:19 PM
Edited Feb 15, 2013 at 12:23 PM
There may be other ways but I use the "CopyIntoItemsLocal" method. I maintain a master library of templates (all kinds of file types) in a read-only library. I have a simple page set up for a user to select a template to use (and provide me a couple other details). Based on some other factors that I look up on the fly, my code figures out what thte metadata should be and where to store a copy of the template, then fires the copy function. After the copy operation is complete, I look up the new item by its "FileRef" property to get the ID. Using the ID, I run the UpdateListItems function on that ID to update metadata. At the end of the script, the page redirects to the target destination library/folder.
Feb 15, 2013 at 6:24 PM
gkoliver,

I tried using the following code to create a copy based on the infopath form template. It still doesn't work.
If possible could you please share the code that works for you??


$().SPServices({
        operation: "CopyIntoItemsLocal",
            async: false,
            SourceUrl: "http://Site/Library/Forms/template.xsn",
    DestinationUrls:["http://Site/Library/test.xml"],       
            completefunc: function(xData, Status) {
                alert("Status=" + Status + " XML=" + xData.responseXML.xml);
            }
        });
Feb 19, 2013 at 1:02 PM
Nothing in your code jumps out at me as wrong. My example (simplified) looks like this:
$().SPServices({
    operation: "CopyIntoItemsLocal",
    async: false,
    SourceUrl: strTemplateSource,
    DestinationUrls: [strTemplateDestination], 
    completefunc: function(xData, Status){
        //console.log(xData.responseText);      //uncomment this line to see the copy result in the console
        if($(xData.responseXML).SPFilterNode("CopyResult").attr("ErrorCode") != "Success"){
            alert("The template copy action failed--please try again.   If this condition persists, please contact the system administrator.");
        }
        else{
            //Do some other stuff
        }
    }
});