简体   繁体   中英

Finding all of the values in a lookup field in SharePoint Online with PowerShell

So I've been having a hell of a time with this. I'm using the SharePoint PnP module to try automate some SharePoint tasks.

Essentially I am trying to add a new item to a list that has lookup fields. The sticking point I have now is trying to add a lookup field value that does not yet exist in the list but it exists in the lookup field.

I can't seem to find a way to capture what exists in the lookup field itself, just what currently exists in the lookup field in the list.

$List_SkillsPerAgent = Get-PnPList -Identity SkillsPerAgent

$DCISkill = (Get-PnPListItem -List $List_SkillsPerAgent -Fields "wsp_ucc_spa_skill").FieldValues.wsp_ucc_spa_skill | Where-Object { $PSItem.LookupValue -eq 'DCISkill' } | Select-Object LookupId -First 1

$PhoneQueue = (Get-PnPListItem -List $List_SkillsPerAgent -Fields "wsp_ucc_spa_skill").FieldValues.wsp_ucc_spa_skill | Where-Object { $PSItem.LookupValue -eq $Queue.Replace('_', ' ') } | Select-Object LookupId -First 1

$Agent = (Get-PnPListItem -List $List_SkillsPerAgent -Fields "wsp_ucc_spa_Agent").FieldValues.wsp_ucc_spa_Agent | Where-Object { $PSItem.LookupValue -eq 'sip:somefakeemail@domain.com' } | Select-Object LookupId -First 1 

The first two steps work fine because those values already exist in the list, however the last one 'sip:somefakeemail@domain.com' does not exist in the list yet so I can't find its LookupID with Get-PnpListItem, however it does already exist in the lookup field wsp_ucc_spa_Agent.

I tried messing around with Get-PnpField but no such luck yet.

Is there anyway to capture all of the values in that lookup field?

The values in the lookup field are stored in the parent list you refer to. To capture all of the values in lookup field. I would suggest you find them in the parent list, the lookupID should be the listItem id in parent list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM