Learn how to interact with URL, User and Look-Up fields read from a SharePoint list.
Prerequisites
This example requires two SharePoint lists.
- States
- Field: Title : Text
- DOT Links
- Field: URL : URL
- Field: State (Look-up field using the title of the States list)
- Field: Owner (User Field)
Script
The script uses the $SPFields Context Item to read URL, Look-Up and User field values from a SharePoint list.
| DOT Links | Copy Code |
|---|---|
|
## Get the DOT links list #set( $myLinksList = $web.lists.get_item("DOT Links") ) #foreach($myLink in $myLinksList.Items) ## Get hard to read SharePoint fields #set( $urlValue = $SPFields.GetUrlValue($myLink.get_item("URL")) ) #set( $stateValue = $SPFields.GetLookupValue($myLink.get_item("State")) ) #set( $ownerValue = $SPFields.GetUserValue($web, $myLink.get_item("Owner")) ) #beforeall <table class="ms-listviewtable" cellpadding="3" cellspacing="0" border="0" width="100%"> <tr class="ms-viewheadertr"> <th class="ms-vh2-nofilter">Title</th> <th class="ms-vh2-nofilter">State</th> <th class="ms-vh2-nofilter">Owner</th> </tr> #odd <tr class=""> #even <tr class="ms-alternating"> #each <td class="ms-vb2"><a href="$urlValue.URL">$urlValue.Description</a></td> <td class="ms-vb2">$stateValue.LookupValue</td> <td class="ms-vb2">$ownerValue.LookupValue</td> #after </tr> #afterall </table> #nodata No links found #end | |
Output
