Creating a Link using a Lookup field

 

Hi,

 

I was just asked a great question: "How do I create a hyperlink when using a Lookup field that points to the item for that lookup field..."

 

This is not completely straightforward, so bare with me. In this example, I am using the Announcements list and the Contacts list. In the Announcements list I created a lookup field the LastName value in the Contacts list and have created a few announcements with the LastName value in them.

 

1. I need to get the List Id of the Contacts list. You can use the web service for this, but I find it much easier to simply drag the Contacts list onto a new page in design view, switch to code view, and Find '@ID' and then grab the list ID (it is a GUID). Then I close that page without saving it.

 

2. Create a new page

3. insert a view of the Announcements list including the Lookup field 4. select the Lookup field data value 5. Insert > Hyperlink 6. type the following into the URL address field:

https://server/subsite/Lists/Contacts/dispform.aspx{ddwrt:URLLookup('{LIST-GUID-FOUND-IN-STEP-ONE}', 'lookup', string(@ID))}

 

(NOTE The nested {} around the GUID).

My URL looks like this:

{ddwrt:URLLookup('{BBD5C595-B540-4839-AAAF-7FB2555A0960}', 'lookup', string(@ID))}

 

7. Save the page

8. switch back to code view and find "mailto:"

9. Delete this. It is a bug that when your URL has an @ symbol in it, FrontPage adds the mailto: code...goofy, but should be fixed in the next release.

10. save the page again

11. Preview in the browser

12. click the Link

 

NOTICE: You should be directed to the dispform.aspx page and see the contact information.