Hi dudes,
i’ve created a Powershell script to create some Lists for a web site using Sharepoint 2010.
Some of these lists have Lookup fileds on them.
The problem is when I apply the same Powershell script in the 2013 version of Sharepoint. Beside the fact all the Lists and fields ara created correctly, when I try to insert an item in the List with a Lookup column in the web site using the Sharepoint 2013 (using thw web browser), the data from the lookup column is not retrieved!!!
Lists structures:
STATES
– ID
– Title
– Country (lookup field for the COUNTRY List)
COUNTRY
– ID
– Title
Have someone else already experienced something similar? How did you fix this problem???
Remember! The lookup field worked fine in SharePoint 2010, but didn’t in Sharepoint 2013!
Follow below the powershell script used:
function New-SPListas
{
Param (
[parameter(Mandatory=$true) ][string]$url,
[parameter(Mandatory=$true) ][string]$NomeLista,
[parameter(Mandatory=$true) ][string]$DescricaoLista,
[parameter(Mandatory=$true) ][string]$codTemplate,
[parameter(Mandatory=$false)][switch]$OnQuickLaunch,
[parameter(Mandatory=$false)][switch]$Sharepoint2013
)write-host “Iniciando criação de lista…”
# ——————–
# Getting the web site
# ——————–
$spWeb = Get-SPWeb -Identity $url# ————————————————————-
# Getting the List template and adding the new List based on it
# ————————————————————-
$spListCollection = $spWeb.Lists
$spListCollection.Add($NomeLista,$DescricaoLista,$codTemplate)if ( $OnQuickLaunch )
{
if ( $Sharepoint2013 )
{
$spList = $spWeb.GetList(“/Lists/” + $NomeLista)} else {
$spList = $spWeb.GetList($spWeb.ServerRelativeUrl + “/Lists/” + $NomeLista)
}$spList.OnQuickLaunch = “True”
$spList.Update()
}$spWeb.Dispose()
write-host “Lista criada: “$NomeLista
}
New-SPListas -url “http://sharepoint-dev/LocadoraWeb” -NomeLista “Country” -DescricaoLista “List of countries” -codTemplate 100 -OnQuickLaunch
New-SPListas -url “http://sharepoint-dev/LocadoraWeb” -NomeLista “States” -DescricaoLista “List of states” -codTemplate 100 -OnQuickLaunch
function New-SPCampos
{
Param (
[parameter(Mandatory=$true) ][string]$url,
[parameter(Mandatory=$true) ][string]$NomeLista,
[parameter(Mandatory=$true) ][string]$NomeCampo,
[parameter(Mandatory=$true) ][string]$TipoCampo,
[parameter(Mandatory=$false)][switch]$Required,
[parameter(Mandatory=$false)][string]$NomeListaForLookup,
[parameter(Mandatory=$false)][switch]$Sharepoint2013
)write-host “Iniciando criação de campo para a lista “$NomeLista”…”
# ——————–
# Getting the web site
# ——————–
$spWeb = Get-SPWeb -Identity $url# ———————————————–
# Adding the new columns to the default list view
# ———————————————–if ( $Sharepoint2013 )
{
$spList = $spWeb.GetList(“/Lists/” + $NomeLista)} else {
$spList = $spWeb.GetList($spWeb.ServerRelativeUrl + “/Lists/” + $NomeLista)
}if ( $Required )
{
$campoObrigatorio = $true
} else {
$campoObrigatorio = $false
}if ( $TipoCampo -eq “Lookup” )
{if ( $Sharepoint2013 )
{
$spListLookup = $spWeb.GetList(“/Lists/” + $NomeListaForLookup)} else {
$spListLookup = $spWeb.GetList($spWeb.ServerRelativeUrl + “/Lists/” + $NomeListaForLookup)
}$LookupListId = $spListLookup.Id
$spList.Fields.AddLookup($NomeCampo,$LookupListId,$campoObrigatorio)
} else {
$spList.Fields.Add($NomeCampo,$TipoCampo,$campoObrigatorio)
}$spField = $spList.Fields[$NomeCampo]
$spView = $spWeb.GetViewFromUrl(“Lists/” + $NomeLista + “/AllItems.aspx”)
$spView.ViewFields.Add($spField)
$spView.Update()$spWeb.Dispose()
write-host “Campo criado: “$NomeCampo
}
New-SPCampos -url “http://sharepoint-dev/LocadoraWeb” -NomeLista “States” -NomeCampo “Country” -TipoCampo “Lookup” -Required -NomeListaForLookup “Country”