How To: Use the SmartObject Hyperlink Property to Navigate to a URL
This topic shows you how to create a SmartObject Hyperlink property and use the hyperlink in a view to navigate to a URL.
Example
Scenario
As part of the sales order process, you may want to check live exchange rates before you place an order. In this scenario, you create a SmartObject called Hyperlinks containing a Hyperlink property, and a Sales SmartObject containing sales details. You create an association between the two SmartObjects and a rule to execute the Get List method of the Hyperlinks SmartObject to show the hyperlink in the Sales Item view. You click the hyperlink to open the live exchange rates URL.
- Create a SmartObject called Hyperlinks with the following properties:
Hyperlinks SmartObject Type Key Required Unique ID Autonumber Yes No Yes SmartObject Hyperlink Hyperlink No No No - Create a SmartObject called Sales with the following properties:
Hyperlinks SmartObject Type Key Required Unique ID Autonumber Yes No Yes Item Text No No No Price per Unit Number No No No Quantity Number No No No Total Number No No No HyperlinkID Number No No No
In this step, you create an association between the Hyperlinks and Sales SmartObjects.
- From the category tree, right click the Hyperlinks SmartObject and click Edit.
- Go to the Associations tab and click Add to open the Add Association wizard.
- On the SmartObject tab of the wizard click Add, select the Sales SmartObject from the Hyperlinks category, then click Next.
- On the Association tab of the wizard, make sure the associations are defined as shown below and click Next.
- On the Relationships tab of the wizard select the ID field and click Assign. Select the HyperlinkID field in the Assign property dialog. Click OK and then Finish.
- The
association shows on the Association tab of the Hyperlinks SmartObject. Click Finish.
In this step, you generate Item views for the Hyperlinks and Sales SmartObjects.
- From the category tree, right click the Hyperlinks 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 Hyperlinks category. Check the Item check box for the Hyperlinks SmartObject and then click OK.
- Use the same steps to generate an Item view for the Sales SmartObject. The views show in the Hyperlinks category.
In this step, you set the Read-Only property of the hyperlink to false so you can update it in the Item view.
- From the K2 Designer, right-click the Hyperlinks Item view and select Edit.
- On the Layout tab, click the hyperlink control of the SmartObject Hyperlink and untick the Read-Only property. This allows you to specify a URL and display value at runtime.
- Click Finish to save the view.
In this step, you run the Hyperlinks view to add details such as a hyperlink for live exchange rates.
- From the K2 Designer, locate the Hyperlinks Item view and click Run.
- Click the hyperlink and then type the URL and Display details. Click OK and then click Create.
- The Live Exchange Rates URL is saved to the Hyperlinks SmartObject for future use.
Note the ID as you will use it in the next step.
In this step, you add a Hyperlink control and a rule to execute the Get List method.
- From the K2 Designer, right-click the Sales Item view and select Edit.
- On the Layout tab, drag the Hyperlink control onto the canvas.
- Navigate to the Rules tab and click Add Rule.
- On the Events tab, select When the View executes a method and then select Initialize.
- Click the Actions tab, then select Execute a SmartObject method.
Select the Hyperlinks SmartObject, Get List method and then click configure.
- Type 1 next to ID on the Input Mappings tab. This is the ID of the Live Exchange Rates record you created earlier. Click the Output Mappings tab.
- Drag the SmartObject Hyperlink from the Return Properties into the Hyperlink control. Click Finish and OK.
- The rule shows in the Rules tab.
- Click Finish to save the view.
In this step, you run the Sales Item view and use the hyperlink to navigate to the Live Exchange Rates URL.
- From the K2 Designer, locate the Sales Item view and click Run.
- Click the Live Exchange Rates hyperlink.
- The Live Exchange Rates URL opens in a new browser tab.