Tuesday, December 18, 2007

InfoPath - Hyper Link with data field

Not mentioned in this article is that you should create another Data Element in your infopath form, example - DynamicHyperLink

concat('http://www.website.com/index.aspx?ID=',DataField)

Be sure to then use that as your data source as indicated below.

 

Create a dynamic hyperlink in a form template

If you want a hyperlink to change depending on values in the form, you can include a dynamic hyperlink in your form template. To create this type of hyperlink, you must bind (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) the hyperlink to a field (field: An element or attribute in the data source that can contain data. If the field is an element, it can contain attribute fields. Fields store the data that is entered into controls.) in the data source (data source: The collection of fields and groups that define and store the data for an InfoPath form. Controls in the form are bound to the fields and groups in the data source.). If the design of your form requires it, you can bind the hyperlink to one field and the display text to another field.

For example, imagine that you are designing a real-estate listing form, which is connected to a database that contains information about properties that are for sale. In the database, you might have a field that contains distinct URLs for each real estate agent. In your real-estate listing form, you can insert a hyperlink and bind it to the field in the data source that contains the URL value. If you want the hyperlink to display the name of the real estate agent rather than the URL, you can bind its display text to a field in the data source that contains the name value. When users click the agent's name on the form, that agent's Web page opens in a browser window.

  1. In design mode, click in the form template where you want to insert a hyperlink, or select the text or picture that you want to turn into a hyperlink.
  2. On the Standard toolbar, click Insert Hyperlink Button image .
  3. Under Link to on the General tab, select Data source, click Select XPath Button image, and then select a field or group.
  4. Under Display, do one of the following:
    • To display a specific string of text for the hyperlink, click Text, and then in the Text box, type the text that you want to display.
    • To have a value inside a control on the form template display as the hyperlink's text, click Data source, click Select XPath Button image, and then select the field or group that the control is bound to.
  5. To assign a ScreenTip that will appear when a user rests the mouse pointer over the hyperlink, click the Advanced tab, and then, in the ScreenTip box, type the text that you want to display.

Tip  You can use XPath (XML Path Language (XPath): A language used to address parts of an XML document. XPath also provides basic facilities for manipulation of strings, numbers, and Booleans.) expressions to create hyperlinks that are a combination of static and dynamic data. For example, imagine that you want to create a hyperlink that links to "http://www.example.com/my name.html" where the Web server name, http://www.example.com, doesn't change, but the file name, my name, varies depending on the data that users type into a specific field in the form. In this case, you would type concat('http://www.example.com/', my:name, '.html') in the Data source box, where my:name is the name of the field to which the text box is bound. The Concat function allows you to combine static text with data from other fields in the form.

Post a Comment