Thursday, February 28, 2013

SharePoint 2010 - InfoPath Forms and Rules


In the previous article we saw the basics of InfoPath forms and the integration with SharePoint 2010. In this article we can explore the InfoPath forms with Rules.
What are Rules ?
A rule in InfoPath is an Action which takes place on an Event. An event could be a field value change. There could be multiple Actions for an Event.
Types of Rules

Please note that there are 3 types of Rules:
  • Validation Rule
  • Formatting Rule
  • Actions
Creating the Form
Open InfoPath Designer 2010 and create a new List from the SharePoint List template. Select your website and enter the name of lists as My Rule List.
p1.png
  1. Validation Rule 

    A Validation Rule validates a field value and displays an error message. We can use range comparison, email validations etc. using this rule.
    We are trying to add a Validation Rule for:
     
    • Email field which will validate itself and show a message if an invalid email is entered
    Use the Add field link from the left pane to create a new field named Email. Once the field is added select the field and from the ribbon menu click the Add Rule button. Then from the menu select the option Is Not an Email Address > ShowValidation Error:

    p2.png

    After selecting the item, you will see that the Rule pane comes into the play. You can use the Rule Pane to manage the rules assigned.

    p3.png

    Now Drag and Drop the Email field to the form. Save and Publish it. 

    Inside the SharePoint site try to enter an email which is invalid and you should get an error as shown below:

    p4.png
     
  2. Formatting Rule
    Formatting Rules are associated with controls rather than fields. In case we need to format the color of a textbox based on a condition this rule is the appropriate one.
    In this scenario we are adding a field named Age.  If the Age is greater than 100, the textbox should turn red in color.  Let us do it.
    Remove the previous field from the form and add a new field named Age. Set the type of field to Number as shown below:
    p5.png
    Now drag the field to our form:
    p6.png
    Once the form is ready, select the Age Textbox and from the ribbon menu choose menu item Add Rule > Is Greater than > Bad:
    p7.png
    You will get the following dialog to capture the Max value.
    p8.png
    Enter 100 as the value and click the OK button.

    Good! Now you are read with the Formatting Rule. Save & Publish the form and inside SharePoint try to add a value greater than 100.
    p9.png
    You will see that the color is changed to red. 
     
  3. Actions
    Now we can try with the Action. Actions allow the following:
     
    • Query Data from other Source
    • Set another Field Value
    • Submit the Form
    • Get Data from a Web Part
    Please note that there could be more than one action associated with a field.
    Our scenario is to have 2 fields:
     
    1. Country of type text
    2. Currency of type text
    When the Country name is India, the Currency must be set to Rupees.

    When the Country name is America, the Currency must be set to Dollars. 

    Let us see how to make this work.

    Now you can remove the previous fields, and add the above 2 fields.
    p10.png
    Now click on the Country field and from the ribbon choose Manage Rules. In the Rule pane that appears, click the New Action button.

    A new Rule will be created. Now click on the Condition link:
    p11.png
    A new dialog will appear. Enter the detail as shown below:
    p12.png
    So this adds our first condition, when the country field is equal to India. Now we have to set the Action for it.

    Click on the Add button from the Rules pane and choose Set a field's value. In the dialog that appears, choose the field Currency and set the value to Rupee:
    p13.png
    Now you have added the condition and action for Rule 1. 

    Similarly you can add one more rule; check for the Country America and set the Currency field to Dollar.

    Now Save & Publish the form. Inside SharePoint try entering India and press the tab button. You will see that the Currency field is set to Rupee.
    p14.png
So this concludes our Actions rule.
From the Rules pane, you can delete / disable a rule based on the requirement.  The changes are reflected in just a Save and Publish.

Add a Data Connection to SharePoint List or Library in InfoPath Form Template


This article will help you bind the SP list or library in InfoPath. Below article contains only few basic steps which will help you to display the sp fields in InfoPath Form template.

Friends, you may be knowing that InfoPath offers 2 type of Data Source: Main & Secondary Data Source.
The Main data source of a form contains the data that you want to permanently store when you save the form. If you want data to be present in a form after you save, close, and re-open the form, you have to store this data in the Main data source of the form. It is automatically created when you create an InfoPath form.

A secondary data source is a temporary storage location for data that is external to the form. Such data typically lives outside the form in databases, XML files, SharePoint lists or libraries, or can be retrieved from web services.

So friends, now it's clear that when we need to show SP List fields in our designed InfoPath Form, then we have to use SP List/library as Secondary Data Source. To achieve the same follow below steps:-
  1. In SharePoint, create a list or library that you can use.
  2. Open InfoPath and-> create a new Blank InfoPath form template.
  3. On the Tools menu,->click Data Connections.
  4. On the Data Connections dialog box,-> click Add.
  5. On the Data Connection Wizard dialog box -> select Create a new connection to->select Receive data and then-> click Next.
  6. On the Data Connection Wizard dialog box -> select SharePoint list or library, and ->click Next.
  7. On the Data Connection Wizard dialog box, type in the URL to the SharePoint list or library you want to use, -> click Next.
  8. On the Data Connection Wizard dialog box, if the SharePoint list or library is not already selected, select the list or library you want to connect to -> click Next.
  9. On the Data Connection Wizard dialog box ->select the fields you want the data source to contain, and -> click Next.
  10. On the Data Connection Wizard dialog box -> click Next.
  11. On the Data Connection Wizard dialog box, type in a name for the data connection or accept the default name, and ->click Finish.
  12. On the Data Connections dialog box->click Close.
After adding of Data Connection to the SharePoint list or library, the form template will contain a secondary data source. Now you can see the Secondary data source from Data source drop-down list. You can view by clicking View and then Data Connection.

Now you can use the secondary data source to the SharePoint list or library on the form template by binding controls to Form Template or by Programming language. 

Creating browser enabled InfoPath forms for SharePoint library


In this article I will explain how can we create and publish browser enabled InfoPath form in SharePoint site. 

Steps Involve

1. Step 1: Design info path form

2. Step 2: Publish InfoPath form

3. Step 3: Open form in SharePo
int 

Step 1 (Design Info Path Form)
  • Open InfoPath 2007 Start>>Programs>>Microsoft Office>>InfoPath 2007.
     
  • Click On File menu and choose Design a Form Template

    1.gif
     
  • In the design template window click on Form Template radio button and select blank. Click on "Enable browser-compatible futures only " to create browser based form 

    2.gif
     
  • Now Design the form using design task window which will be appear in the right side.

    3.gif
     
  • Click Layout link to design layout of the form.

    4.gif
     
  • After design click on Controls on Design Task pane to add control in your form.

    5.gif
     
  • Go to Tools menu and select Data Connections

    6.gif
     
  • In data connection window click on Add button to create new data connection.

    7.gif
     
  • Now Data Connection Wizard will be open to create data connection. Click on Create New Connection radio button and choose Submit Data, click on Next

    8.gif
     
  • Select destination where you want to submit data(In this article I will submit data in share point document library). Select destination "To a document library on a SharePoint site" and click on next button.

    9.gif
     
  • Specify the URL of SharePoint document library and file name. Click on next button 

    10.gif
Steps for Creating dynamic file name:
  1. Write "CustInfo" in File name text box and Click on "fx" button.
  2. A popup will be open to insert formula.

    11.gif
     
  3. Click on "Insert Function" button and select Categories Text and function concat and click on Ok button .

    12.gif
     
  4. Delete first text from concat function and Double Click on next "double click to insert field" text and select CustName Field. Delete next text also. 

    13.gif

    14.gif
  5. Click on "OK" button.

    15.gif
Dynamic form name created now click on next button.
  • Specify the name of submit data connection. And click on Finish button.

    16.gif
     
  • Now new submit data connection will be created. Click on Close button to close wizard.

    17.gif
     
  • Now go to Form Options Tools>>Form Options. Uncheck show toolbar check boxes.

    18.gif
     
  • Click on Ok button to save your changes.
     
  • Right click on button control (which you have added in your form) and select button properties.

    19.gif
     
  • Select Submit from the "Action" dropdown and Change the label of button and click on "Submit Option" button. Click on "Submit Option" button.

    20.gif
     
  • From submit options popup, Click on "Allow users to submit this form " check box, select "Perform custom action using Rules" and click on "Rules" button.

    21.gif
     
  • From rules popup click on "Add" button for adding rules.

    22.gif
     
  • From rule window click on "Set Condition" button to add validation. 

    23.gif
     
  • From condition window select custName and "is Not blank" from the dropdown list and click on "Ok" button. 

    24.gif
     
  • Now click on "Add Action" button to define rule.

    25.gif
     
  • From Add Action window select "Submit using a data connection" from Action dropdown and select name of submit data connection. Now click on "Ok" button.
Step 2 (Publishing Info Path Form)
  • From the design task pane click on "Publish Form Template". From publishing wizard select ffirst option to publish form in share point and click on next button. 

    Step2.1.gif
     
  • Enter the URL of SharePoint site and click on next button.

    Step2.2.gif
     
  • From the next window select "Document Library" and click on next button. 

    Step2.3.gif
     
  • From next window select "Create a new document library" option and click on next button.

    Step2.4.gif
     
  • Enter the name and description for new Form Library and click on next button.

    Step2.5.gif
     
  • Click on "Add" button to add column in library. 

    Step2.6.gif
     
  • Select field and enter the column name in "Column name" text box and click on "Ok" to create column. (Do the same step to create columns for Age and Address)

    Step2.7.gif

    Step2.8.gif

Click on Next button.
  • Click on Publish button to publish form.

    Step2.9.gif
     
  • Now form is published on SharePoint library.

    Step2.10.gif

Step 3 (Open InfoPath form in SharePoint)
  • Go to SharePoint site, open "CustDetail" library, click on Settings and select "Form Library Settings".

    Step3.1.gif
     
  • Select "Advanced settings" from general settings group.

    Step3.2.gif

     
  • From Advance Settings window select "Display as a web page" option from the "Browser Enabled Documents" section and click on Ok butom.

    Step3.3.gif
     
  • Now go back to your document library click on "New" menu and select "New Document" to open InfoPath form.

    Step3.4.gif

     
  • Now InfoPath form will be open in the browser. Fill data and click on Save Data button to submit data in library.

    Step3.5.gif
     
  • Go back to "CustDetail" to view your data.

    Step3.6.gif