Saturday, January 26, 2013

Getting a specific list view as a data source in Infopath


1.       Create the view you intend to pull in SharePoint. Make sure to sort it and filter it the way you want it to appear in the drop down.
2.       Click on Settings->List Settings to get to the settings of the list you want to use.

3.       Scroll to the bottom where it shows views and click on the view that you want. This should be where you would edit the view.
4.       Go up to the URL and copy everything after List= (this is the GUID of the view).
5.       Place what you have in notepad.
6.        Replace %7B with { (this should be first part.
7.        Replace %7D with } (this should be the last part.
8.       Replace %2D with a –
9.       You should have something that looks like
{FCE658C5-54A5-4460-B9F4-6EE4CBF017D7}
Note:the numbers and letters are unique to your view but the formatting should be the same.
10.   Take the url of the site where the list resides and put it in front of the GUID
11.   Now you have the pieces to build your string. The format of the string is
<URL>/_vti_bin/owssvr.dll?Cmd=Display&List=<ListGUID>&View=<ViewGUID>&XMLDATA=TRUE
for example: 
http://site/_vti_bin/owssvr.dll?Cmd=Display&List={FCE658C5-54A5-4460-B9F4-6EE4CBF017D7}&View={B9BC3880-739B-4DA0-89A7-716775E755B7}&XMLDATA=TRUE
12.   You now have the string you need to create the data connection in Infopath.
13.   In Infopath you need to add a data connection.
14.   Create a new connection to receive data. Click OK.
15.   Choose XML document. Click OK.
16.   Paste the string you created in notepad into the Enter the location of the XML data file that you want to use as your data connection.
17.   Click next and okay until you are out of the wizard and you are ready to use your data source. If you are given a security prompt you can just click cancel.
18.   Note: everyone that uses the form must have read access (at least) to the list you are pulling from.

This article was taken from Michael Doyle from SharePoint Ninja

http://www.sharepointninja.com/Blog/Lists/Posts/Post.aspx?ID=13

New Certification - MOS Office 365


Ignore and clear all errors in a form before submit

Problem: You want to be able to submit an InfoPath form despite any data validation errors that the form may have, so you want to ignore and delete all validation errors before submitting the form.


You can use the DeleteAll() method of the Errors collection to clear all of the errors in a form:

To Ignore and clear all of the errors in a form before submitting the form:

1 - Create a new form template

2 - Add a Textbox control to the view nad make it a required field by selecting its Cannot Be Blank Property.

3 - Go to the Submit Option under File and select "Allow users to submit this form" check box, select the "Perform custom action code option, deselect the "Show the Submit button in both the ribbon and the info tab in the InfoPath Filler". Click on Edit Code.

4 - Add following code to the FormEvents_Submit() event handler


Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
            ' If the submit operation is successful, set
            ' e.CancelableArgs.Cancel = False
            ' Write your code here.
            System.IO.File.WriteAllText("C:\Temp\myform.xml", MainDataSource.CreateNavigator().OuterXml)
            e.CancelableArgs.Cancel = False
        End Sub


You will need to give the form full trust in order to save it to disk

5 - Add a button control to the view and label it "Submit". Add the following code to the clicked event handler of this button


Public Sub CTRL2_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
            ' Write your code here.

            If Me.Errors.Count > 0 Then
                Me.Errors.DeleteAll()
            End If

            Submit()

        End Sub

* The first three lines of code delete all of the errors that are in the Errors collection of the form, and the fourth line of code calls the FormEvents_Submit() event handler to submit the form.

6 - Save and build project

7 - Preview the form.

When the form opens, a red asterisk (*) should appear in the text box as an indication that it is a require field. Click the button.  The form should be submitted without warning you about any data validation errors.

About Me

My photo
Toronto, Ontario, Canada
MBA, M.Sc. & MCP