RenderForm with SaveToSharepoint Command - Mark Tienzo
in

InfoPath Dev

This Blog

Syndication

Tags

No tags have been created or used yet.

Archives

Mark Tienzo

RenderForm with SaveToSharepoint Command

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 SaveToSharepoint command?

            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 SaveToSharePoint command:

·         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 attach

·         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 location.

 

Important 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 command only:

                Here is the form

 

                 The 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.

                On the button control, I added a rule to set the qRules Command field to:

concat("SaveToSharePoint /url= http://<servername>/MyDocLib /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 clutter in my main data source. The xml file looks like this in Notepad:

<FormLogic>

                <Values>

                                <RenderedForm qRulesLink="" qRulesFilename="" />

                </Values>

</FormLogic>

 

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 their importance):

 

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.

1.       Set the qRules Command field to: RenderForm /allviews=true /resultxpath=/FormLogic/Values/RenderedForm /resultdestds=RenderForm

2.       Set the qRules Command field to: concat("SaveToSharePoint /url= http://<servername>/MyDocLib /dsname=RenderForm /xpath=/FormLogic/Values/RenderedForm /name=", my:FileName)

3.       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!

Comments

 

tyty4u2 said:

I am looking at using this feature to Archive a form.  So once the form is marked completed, this will renderform as HTML and then submit to a document library leaving a hyperlink in the form.  

My question is what happens when there are images in the table of the form, such as a picture header?  I know image files themselves cannot be embedded in an HTML document so would they be put in a folder in the library or would they be ignored?

Thanks in advance!

February 3, 2013 9:03 PM
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.