Adding Formulae to Fields
Our Item data element contains two columns,
LineTotalCost and LineTotalValue, that should be calculated based on
the values entered in other columns in the row. To add formulae for
these fields, take the following steps:
Select the Line Total Cost text box in the repeating table control. From the Properties tab in the ribbon, select Default Value.
In the Field Or Group Properties dialog, click the fx button next to the Default Value text box.
Using the Insert Field or Group button to select the appropriate fields, add this formula, as shown next: Quantity * StandardCost.
Repeat the process for the Line Total Value text box. This time add this formula: Quantity* ListPrice.
To
prevent users from entering values in these calculated fields, we need
to change them from text boxes to labels. Click the Change Control
option from the Properties tab on the ribbon, and then select
CalculatedValue.
Publishing a Form Template to SharePoint
Our basic Demonstration Equipment Request form is
now complete. To publish it to SharePoint and use it for capturing data
for our Demonstration Equipment Request library, take the following
steps:
As we did earlier, from the backstage area, click Publish Form To A SharePoint Library. Type the server URL as http://<YourServerName>/Chapter5. When prompted, save a copy of the form named EquipmentRequest.xsn to the local file system.
Select
Form Library from the list of options, and then select the
Demonstration Equipment Requests library. Click Next to move to the
next step of the wizard.
When
we published our simple form earlier, we skipped this section. Since we
want to capture data from our equipment request form, we need to
specify which fields we want to include as columns in our document
library. By clicking the Add button in the upper section of the form,
add all fields within the Customer group to the library, as shown:
Click Next and then click Publish to add the form to our library.
Using the browser to navigate to the Demonstration
Equipment Requests library, you can see that by clicking the New
Document button on the Documents ribbon, our InfoPath form is
displayed, allowing us to enter details as expected. To store the form
in the document library, we must use the Save option and name the form.
By performing this step, we’re saving a copy of the form in the
document library and at the same time copying the field values that we
specified earlier into columns.
Creating Custom Forms for SharePoint Lists
Another use of InfoPath forms, and one that’s become
more prevalent with SharePoint 2010, is in the creation of custom new
and edit forms for SharePoint lists. Custom forms differ from the form
templates that we saw earlier: the form itself is not stored in the library.
Since custom forms can be used only with lists, only the field data
that we elect to include is copied to columns in the list as opposed to
the entire completed form. Let’s create a custom form for a SharePoint
list:
Using
SharePoint Designer, create a new custom list named MyCustomList. From
the Lists and Libraries navigator, double-click the MyCustomList icon
to manage the settings for the list.
In
the List Settings tab of the ribbon, select Design Forms in InfoPath |
Item. InfoPath Designer will then open, displaying a basic template for
capturing list item data.
Additional
fields can be added using the Add Field link in the Fields pane. When
you add a field to the form, a column is also added to the underlying
list to store the captured data. For example, we could add a field
named Description. Once the form is published, a new column named
Description will be added to our custom list.
To publish the customized form, click Info in the left pane and then click the Quick Publish button in the backstage area: