Mark Tienzo

InfoPath Dev

This Blog



No tags have been created or used yet.


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:

    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:



                                    <RenderedForm 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 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!

  • RenderForm Command

    The new “RenderForm” command

                When qRules 4.3 was launched last December 21, 2012 one of the newest commands was RenderForm. This command generates an HTML rendering of one or more of the form’s views.  In other words it gives us the ability to output a rendered copy of the form in a browser, by saving it as an HTML file, or it can provide us the rendered form as HTML code that we can edit or save using a text editor, e.g. Notepad, Notepad++, to later view it in a browser.


    What are the parameters used in RenderForm?

    views(optional): you can indicate which view to render, or render multiple views in one HTML file by listing the views you want separated by ampersands (&).

    allviews(optional): specify “true” for this value to render all of the form’s views in a single HTML file



    output(optional): possible values are:

           base64 which is the default and outputs the rendered HTML as a base64 InfoPath attachment, which can be used in an attachment control

           raw which outputs the rendered HTML as a string value

    filename(optional): Allows specifying a filename for the output HTML file. This is only applicable when using base64 output. The default value is “rendered.htm”.


    Some points to remember…

           This command requires the form to be full trust.

           Do not use both the /allviews and /views parameters at the same time.

           This command is not compatible with MOSS 2007 browser form but is compatible with SharePoint 2010 browser forms.

           View names are case-sensitive.

           If specifying a filename, always include an extension for the filename.

    Here are an example I have created for you…

    The screenshots below are from a form I created with four simple views to help us understand and also have a visual idea of how RenderForm works.  By having this visual representation you can see how different page layouts, colors, text, etc. will look in the browser.

    I called the first view Render Command. I placed some of the possible combination of commands we can use on a button control:


    The second view is called PAL.


     This is the third view and it’s named NBA.


    The last view is called Sort.



    We are going to use the Render Form view to use some of the RenderForm commands…

    The first button renders all the views available on the form, and the command used is listed as the button's text.  I used a rule to copy the value of the Result field of the QdabraRules data source to a file attachment control right after the RenderForm command is run.  The filename that will appear in the file attachment control will be rendered.htm since we did not specify any filename and because this is the default filename.  We can view the form in a browser by right-clicking the file attachment then saving it or by opening it directly.

    (all four images below are displayed in a single browser tab)

    The second, third and fourth button renders only the view which is stated on the label of the button, PAL view for the first button, Sort view for the second button and NBA view for the third button. The filename will also be rendered.htm for the three commands.

    (all three pictures below are viewed on separate tabs of the browser)


    The fifth button renders the PAL, Sort and NBA view only omitting the Render Form view since it is not included in the command.  The filename will also be rendered.htm.

    (images are the same as the first button except the Render Form view is omitted)


    The sixth button renders the PAL view only but this time renames the filename to PAL.htm instead of the default rendered.htm. We could also omit the "/output=base64" since this is the default value for the command.

    (this is viewed from the preview of the Render Form after clicking the sixth button.  The rendered view is the same as the result of clicking the second button)


    For the seventh and eighth button we used a different output type called "raw".  This will not give us an htm file that we can directly view in a browser but gives us the HTML code.  I used the text box to copy out the value of the Result field of the QdabraRules data source.  This value can be copied to a text editor where you can edit and save it as an htm file to view it in a browser.  We cannot specify a filename because it would not be relevant here.

    (this is viewed while previewing of the form after clicking the seventh button)




Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.