3

I'm trying to get the value behind a list item that is a lookup field. The list item is a clickable string that has a URL attached to it. Here's a screenshot (German language, though). enter image description here

I want to retrieve the URL. The column is of the type "Microsoft.SharePoint.Client.FieldLookupValue".

Here`s what I have to so far:

$spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials $credential.UserName, 
$credential.Password

$site="https://contoso.sharepoint.com"
$ctx= New-Object Microsoft.SharePoint.Client.ClientContext($site)
$ctx.Credentials = $spoCred

$lists = $ctx.web.Lists
$list = $lists.GetByTitle("Workspaces")
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$ctx.load($listItems)

$ctx.executeQuery()

ForEach($listItem in $listItems)
{
  $lookup = [Microsoft.SharePoint.Client.FieldLookupValue]$listItem["Url"]
  $lookupValue=$lookup.LookupValue
  $lookupValue
}

Unfortunately, $lookupValue is empty. Authentication works fine and $listitems returns all rows in the list. Any ideas?

  • I'm confused by your question. Could you please elaborate if your lookup column on list Workspace indeed is called "Url"? – Andreas Jun 7 '17 at 12:06
  • Thanks, I added a screenshot. In other words, I want to get the URL that's behind each list item in the 'URL' column - the 'FFLB' list item, for example. – colonel_claypoo Jun 8 '17 at 5:53
  • German here too. Have you tried to access $lookup.LookupId? I don't see the url (also confused by the fact that title in the shown list and lookup list seems to be identical, can you attach screenshot of list where lookup is directed to?). FieldLookupValue only contains listitem id of the referenced SPListItem and the title (string). If the referenced SPListItem also contains an url you would need to get LookupId and load item in the 2nd list – Andreas Jun 8 '17 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.