How To: Use SmartObject properties in a Hyperlink Expression to Navigate to a URL
This topic shows you how to use SmartObject properties as parameters in a hyperlink expression. It includes how to use the expression on a Hyperlink control to navigate to a URL.
Example
Scenario
As part of the sales order process, you may want to check live exchange rates before you create an order. You click the hyperlink to open the live exchange rates URL. In this scenario, you use SmartObject properties as parameters in a hyperlink expression to configure the Hyperlink control. The hyperlink expression contains two parameters, Display and URL, both in text format.
In this step, you create a SmartObject with Display and URL properties.
- Create a SmartObject called Sales Order with the following properties:
Sales Order SmartObject Type Key Required Unique ID Autonumber Yes No Yes Item Text No No No Quantity Number No No No Price per Unit Number No No No Total Number No No No Display Text No No No URL Text No No No
In this step, you use the generate function to create an Item view for the Sales Order SmartObject.
- From the category tree, right click the Sales Order SmartObject and click Generate Views.
- On the Generate Options page, in the Views section, make sure that the views are generated in the correct category. In this example they are generated in the Sales Order category. Check the Item check box for the Sales Order SmartObject and then click OK.
- The view shows in the Sales Order category.
In this step, you update the properties of the Display, URL and Hyperlink controls, you add an expression to the Hyperlink control, and you use the Display and URL SmartObject properties as parameters in the expression.
- From the K2 Designer, right-click the Sales Order Item view and select Edit.
- On the Layout tab, select the Display text box and untick the Visible property of the control.
Do the same for the following:
- Display label
- URL label
- URL text box
- Rearrange the Display label and the Display text box by dragging them to the positions shown below.
- Drag the Hyperlink control onto the canvas, untick the Read-Only property, and then click the ellipsis next to the Expression property.
- Click Add to add an expression and then type Navigate to Live Exchange Rates in the Name field.
- Drag the Hyperlink function from the Context Browser onto the canvas as shown below.
- Click the Context tab and drag the Display and URL SmartObject properties to the parameter boxes as shown.
Click OK and OK again.
- Click the URL text box and change the Text to https://www.xe.com/?. This is the URL to open when you click the hyperlink at runtime.
- Click the Display text box and change the value to Live Exchange Rates. This text displays in the hyperlink.
- Click Finish to save the view.
In this step, you run the Sales Order Item view to add some sales details. You can click the hyperlink if you want to view exchange rates before you create an order.
- From the K2 Designer, locate the Sales Order Item view and click Run.
- Click the hyperlink called Live Exchange Rates.
- The Live Exchange Rates URL opens in a new browser tab.