Welcome to TechNet Blogs Sign in | Join | Help

Binding document content to Document Information Panel in MOSS2007

Today I will talk about the possibility to bind the content of a Word 2007 document to it Document Information Panel in SharePoint 2007.

This is quite a useful feature as the content of documents can be automatically populated via the metadata and viceversa.

The trick is done by Content Controls.

 

Let’s create a document library named “To Be Approved”. Let’s add some required columns to this document library. I have added a column named “Approver” (single line of text, required) and another column named “Date Approved” (date time, date only, optional).

 

Let’s now create a new Word 2007 document from our document library.

Let’s insert a header (I chose the “austere” style formatting) and save the file locally as a docx. This is the most important step as Content Controls are only available in Open XML documents.

Continue editing the header of the file: insert a Quick Part -> Document  Properties and choose Approver (our sharepoint column).  Do the same for “Date Approved” field.

 

Header 

Note that if you modify the value of either Approver or Date Approved fields the content of the document will change accordingly, and vice versa modifying the date in the header the metadata will change.

 

Now let’s go back to our document library: document Library settings, Advanced Settings: and enable content types.

Click on “Document” under Content Types and go to advanced settings. Check Upload a new document template and browse for the file we just finished editing.

Now go back to our library and click on New: a new docx file will open.

Edit metadata (approver, approved Date, Title), you will see the header updates with the metadata values you’ve just entered.

 

Note. You can bind any part of a docx file to metadata. I chose a header just for the purpose of demonstration.

 

 

Posted by eterenzi | 1 Comments

Designing a browser-enabled InfoPath form that can store data in a database - Part3

Here's the last part of this blog post.

We will finish creating the form and we will test it.

 

Now create another section named DiscountData, insert a table with title and another table with three columns and four rows as follows:

Discount data section 

startDate and endDate are date pickers controls, discount rate is a textbox.

This section will contain the discount data that will be stored to the database via our web service.

To make this form more "robust" you could set the visibility of this section to depend on the shopID value: in the Display properties of the discountData section click on conditional formatting and add a rule that hides this section if shopID field is blank.

To send data to our web service, we will configure the “Save!” button to do our job but first we need to create the data connection and store it to the data connection library in SharePoint.

Now in the data source section choose manage data connections and add a data connection. The Data Connection Wizard will start: choose “Create a new connection to”->“Submit data” then click “Next”. Select “To a Web Service” and then click “Next”. Now insert the location of the web service: http://youservername/sql?wsdl and then select the name of the webservice (in our case StoreDiscountData) and click Next. Now you will be able to bind the required parameters to the controls in our InfoPath form: s0:shopID to our shopID textbox and so on (see below).

Data connection binding

Now click Next, give a name to this new connection, click on Finish, and OK until you will close all open dialogs. Now, like we did for the other data connection save this data connection to our data connection library, delete the one in the form and re-create it adding it from the sharepoint data connection (you will have to re-bind the parameters to the ones in our form).

Now double click on the button "Save!" and add a rule with an action to submit using our newly created data connection. 

Back to the Rule window: we want the form to be closed after the data is stored therefore choose: Add Action, and select Close this form (no prompt will be automatically selected as we are using Form Services forms). Click OK until you close all windows.

We also need to save this form in a SharePoint document library in order to make it editable with a browser using Form Services.

If you haven’t saved the form so far, then it’s time save the form template locally.

Now select File->Publish and choose “To a SharePoint server…” and click Next. Insert the URL of your SharePoint and click Next. In the next step check the “Enable this form to be filled out by using a browser”, select Document Library and click Next. Select Create a new document library and click Next. Give the document Library a name (like “Discount Forms”) click Next and select the columns you will want to promote as Document Library columns (i.e. you will see the data in each form exposed as columns in the newly created document library). Click Next and click Publish. If everything is OK you will be noticed your form has been successfully published to your SharePoint. 

Form is published

We are not done yet: we also want to specify the form name therefore we will add another rule to our Save button: double click on the button, click on Rules->Modify->Add Action. Select submit using a data connection and select Add. The data connection wizard will start again, and again we will choose Create a new connection to Submit data and then click Next. Choose “to a document library on a SharePoint site” and click Next. Now insert the URL of the document library where we have just published our form and edit the rule that will generate the name of our form – in my case: concat(shopID, "_", concat(startDate, "_", concat(endDate, "_", discountRate))). Click Next and Finish. Click OK until all windows will close.

Save the template and re-publish the template to our document library (it should be just a Next-Next, this time choose “update the form template”).

One final step: in case you want the form to only e filled out with a browser:

Go to the Document Library where we published our form template. Select Settings->Form Library Settings and click on advanced settings: click on “display as a web page” and click OK. Now every time you will click on “New” the form will open directly in the browser.

 Now we are

Browser enable the form

 Now we are lef with testing the form.

Go to back to your document library and click on New. the form should open in  the browser.

Insert some data and click on the Save button: the form is saved to SharePoint and the discounts are saved in our Discount table in SQL Server.

Designing a browser-enabled InfoPath form that can store data in a database - Part2

In the last post we have set up the DB that will receive data from our InfoPath forms. Now we will create the InfoPath form.  

Creating the form

Now we’re left with the easiest part: creating our InfoPath form.

Since I am using a SQL Server DB I won’t need a web service to retrieve data as InfoPath knows already how to do this with a SQL Server DB, but if you will be using other Database types, you will have to create another webmethod in the endpoint definition in order to map a web service name to a stored procedure.

 

Start InfoPath 2007 and choose “Design a Form Template…” from the “Design a form” options.

Design Form Template

Choose to design a new form template based on “Blank”. This will just create a form that is empty.

Choose Tools->Forms Options and in the “Compatibility” section select “Design a form template that can be opened in a browser or InfoPath, uncheck “Hide errors…” and enter the URL of your SharePoint server (http://servername:portnumber).

In the “Security and Trust” section, uncheck “Automatically detect security level” and choose “Domain”. If the DB to which you will be connecting isn’t a member server of the domain, then you will have to set the security level to “Full Trust” and you will have to sign the form.

Now on to designing  the content of the form:

Create a section named ShopIDgroup that contains a table with title (Design Tasks -> Layout-> Table with Title – see below)

form layout controls 

Then add a table with three columns and one row: make the table containing a text box control named shopID and a button as shown:

form welcome 

Double click on the button and select Rules->Add->“Add Action”: in the data connection section select “query using a data connection” then “add”. The data connection wizard will start: select “create a new connection to:” then “receive data” then click “next”; at this point select “database” if you have a SQL server DB (if you don’t have a SQL Server DB here you will have to select “web service” and then you will be prompted to connect to the server that exposes the web services and select your webservice) and click “next”. Now click on “select database…” and then in “my Data Sources” select “+newSQLServerConnection.odc”, this will start a data connection wizard where you will have to insert the name of the SQL server on which your db resides and select the database and table to which you are willing to connect (in our case the database name is InfoCityHall and the table is “Shops” (see below).

Data Connection Wizard 

Click next and Ok you will return to the InfoPath wizard. Make sure you have selected all the columns of the Shop table and then click Next, Next and Finish. Then click OK till all the dialog boxes will close.

Now that we have set up the connection we need to store it in a Data Connection Library in SharePoint (this is mandatory for browser enabled form to access external data).

In the Data Source section click on Manage Data Connections, select the "Shops" data source and click on the Convert button, insert the URL of your data connection library (if you haven’t created one so far, create one in the same site collection as the one where you will store the forms) – the URL must include the udcx file name and make the data connection file relative to site collection and click OK.

Convert Data Connection

Now delete the Shops connection and create another one as follows: in the data connections wizard, select Search for connections on SharePoint, Next. Select your SharePoint site and select the data connection (in our case Shops.udcx) click Next, Next (unselect automatically retrieve data when form is opened) and Finish and close the data connections window.

Open UDC connections 

Now back to our form design: add another section named ShopData: this section will expose the info about the Shop that has been retrieved from the ShopID above.

Insert a table with two columns and three rows as follows:

Form fieds 

shopName, shopAddr and shopOwner are all textboxes.

For each one of those controls: go to the control Properties and as the value of the control select the relevant column from the Shops table as follows: click the fx button, Insert a Field or Group, Data Source: Shops(secondary), select the relevant column and click on Filter Data then click Add and set the filter to ID is equal to shopID (from the main data source).

Repeat this for each one of these controls.

Filtered Field value

We will finish designing the form in the next blog post.

Designing a browser-enabled InfoPath form that can store data in a database - Part1

 

As I haven’t found so far any blog post explaining how to design an InfoPath form that could save its data to a database I decided to write this post. I hope the content is useful. Any feedback is appreciated.

Assumptions:

The goal is to create a web-enabled form that is able to both retrieve and store data in a database.

Used technology:

You will need Infopath 2007 to design the form, a Form Services enabled server (either SharePoint Server 2007 or Form Server 2007) and a database server that is able to expose web services (I will use SQL Server 2005).

Scenario:

A city hall needs to receive data from shops regarding discounts, in particular the discount type (30% off, 40% off, etc) and the period during which the discount will be applied.

Let’s assume that the shops are already registered in the city hall database.

The forms will retrieve the shop data based on the shop ID (that the owner will already know) and the owner will post data regarding the period and the discounts that will be applied.

Please take this as an example, the important part is setting up the form to talk to the DB and send data to it.

 

Set up the DB

The DB (InfoCityHall) will contain two tables: one for the SHOPS(ID, NAME, ADDRESS, OWNER) and one for the DISCOUNTS(SHOPID, STARTDATE, ENDDATE, DISCOUNTRATE).

The data already inserted is the following:

SHOPS

1

Pike and Pine

1025 Pine Str.

John Smith

2

Leo’s

903 S. Racine Ave.

Mark Johnson

3

Michigan Place

100 N. Michigan Ave.

Glenn Hughes

4

EleStore

302 N. Springfield Str.

Spider Pork

 

use infocityhall

 

insert into shops values (1,'Pike and Pine','1025 Pine Str.','John Smith')

insert into shops values (2,'Leo’s','903 S. Racine Ave.','Mark Johnson')

insert into shops values (3,'Michigan Place','100 N. Michigan Ave.','Glenn Hughes')

insert into shops values (4,'EleStore','302 N. Springfield Str.','Spider Pork')

 

select * from shops

 

DISCOUNTS is empty. InfoPath will insert data into it.

 

Set up the Web Service

Now  we will need to create the web service. We will use the web service to store discounts into the DB from InfoPath.

The Web Service in SQL Server is created through an “HTTP Endpoint” and a T-SQL stored procedure.

Here is the stored procedure

create procedure StoreDiscount

@ShopId numeric,

@StartDate datetime,

@EndDate datetime,

@DiscountRate int

as

BEGIN

insert into discounts values(@ShopId,@StartDate,@EndDate,@DiscountRate)

END

 

And here is the HTTP Endpoint:

CREATE ENDPOINT discount_endpoint

STATE = STARTED

AS HTTP (

   PATH = '/sql',

   AUTHENTICATION = (INTEGRATED ),

   PORTS = ( CLEAR ),

   SITE = 'YourSqlServerName'

        )

FOR SOAP (

   WEBMETHOD 'StoreDiscountData'

            (name='infocityhall.dbo.StoreDiscount',

             SCHEMA=STANDARD ),

   WSDL = DEFAULT,

   SCHEMA = STANDARD,

   DATABASE = 'infocityhall',

   NAMESPACE = 'http://tempUri.org/'

        )

The web service will now be discoverable at the location http://yoursqlservername/sql?wsdl

In the next post we will start designing our InfoPath form.

 
Page view tracker