Good day readers. Today we are going to talk about the SaveToSharePoint
command and how you can use it in conjunction with the RenderForm command. If you are not yet familiar with the
RenderForm command, I suggest you have a look at my recent blog about it before
continuing this one.
This link will take you to RenderForm blog: http://www.infopathdev.com/blogs/mark_tienzo/archive/2012/12/30/renderform-command.aspx
What is the
This is one of qRules’ advanced commands. It lets us save a file, a set of
files, an image, or a set of images to a SharePoint document library. We need to have access to a SharePoint site
and have a SharePoint document library created in advance in order to do this.
Let’s look at the parameters that we can use with the
url: This is the URL where the SharePoint document library is located.
xpath: Here we indicate the xpath of the file or image attachment within the form.
dsname: This is the name of the data source
where the file field is located, if it is not in the main data soure.
name: This is optional. We can specify a filename for the file if we want, and if not, the command will generate a name. If name
is omitted, it will also automatically add an extension for the files or images we
overwrite: Also optional, and the
default if we omit this is to not overwrite. overwrite allows overwriting files with the same filename if set to yes. This is
unavailable if you use the /dsnamews parameter
dsnamews: This is a data
connection name for copy web service(optional).
dsurl: (optional) If we use the Copy web service
data connection option with this command, the /url parameter needs to be to the
same site that the data connection used. That is, if I created my data
connection to the copy service using http://serverA but my command url is
http://serverB (and therefore my form is published to serverA), the web method
will fail. The /dsurl parameter can be used with the /dsnamews parameter to
change the service url of the data connection to match the /url
points to remember when using this command:
The file or image field we create should have attributes with the names qRulesLink and qRulesFilename (both case sensitive) for this command to work.
If we need to
upload more than one file/image, the source field should be in a repeating structure, but it should not be a repeating field within a repeating group.
If there are no attachment(s) the command will perform no action, so make sure you
have a file attached or make a rule so that it only
executes when the field is not empty or blank.
Let’s get started by creating a simple form with the SaveToSharePoint
form consists of a file attachment control(FileAttachment), a
textbox(FileName), a button(where the command will be placed), and another textbox(URL)
to display the URL of the file saved.
Notice I encircled the qRulesLink and qRulesFilename attribute just to
give emphasis to how important these attributes are to the command.
button control, I added a rule to set the qRules Command field to:
/xpath=/my:myFields/my:FileAttachment /name=", FileName)
If executed properly, this will send the
file to the SharePoint library with the filename you entered, as seen in the
picture above. See how simple it is?
Now we are going to integrate this
command with RenderForm. I used the form
from my previous blog but tweaked it a little to make the SaveToSharePoint and
RenderForm command work together. Before working on the actual form changes, I created an xml file
to use as a secondary data source
to prevent unnecessary
my main data source.
The xml file looks like this in Notepad:
qRulesLink="" qRulesFilename="" />
This file looks like this in the form when we add it as a secondary XML data source (notice I encircled the
attributes again to emphasize
Now here is the
main/default view we are going to use:
On each button control I used three rules one to render the
view, the second to save it a SharePoint library, and the last to display the
URL of the file saved.
Set the qRules
Command field to: RenderForm
/allviews=true /resultxpath=/FormLogic/Values/RenderedForm /resultdestds=RenderForm
Set the qRules
Command field to: concat("SaveToSharePoint /url=
/dsname=RenderForm /xpath=/FormLogic/Values/RenderedForm /name=",
Show a dialog
box: concat("File saved to
SharePoint library. URL is ", xdXDocument:GetDOM("RenderForm")/FormLogic/Values/RenderedForm/@qRulesLink)
If I clicked all the buttons and had them name each file True,
Airlines, Sort, Basketball, AirlinesSortBasketball respectively, this is how it
would look in the SharePoint library:
Now I hope you’re excited to see how the file will
look when we open it. Click on the
filename, then save, then open (I
am using Internet Explorer in this case).
Here is what it looks like when we click on the topmost file which is
AirlinesSortBasketball on a tab of Internet Explorer:
This is how we can use the SaveToSharePoint and RenderForm
command together. I hope you learned
something from this. Try it out to see how simple it is to use
these commands in qRules!