Hi All,
Recently I have come across an issue where I needed to use PowerShell to update a particular field options. Moreover the field is a Lookup field. Our problem is that, we have more number of related lists in our application, where we are lookup the parent list item id in the child list item. So security reason we have set "Restrict Delete" in the Enforce Relationship behavior for the Lookup field. At this point we have set the lookup for a single field. (So we have not allowed Multiple lookup value).
Unfortunately we got a situation for multiple selection in the lookup field. By default in SharePoint 2010, Enforce relationship behavior will not available if we allow to select multiple values for the lookup field.
The above snapshot describes the default behavior of the lookup column with Allow multiple values. My current scenario also is the same, i need to enable the Allow multiple values for the lookup field.
Problem Definition:
When set Enforce relationship behavior for the lookup field, the column must be indexed. So the column which we have given restrict delete was indexed and now i am not able to enable Allow multiple values option,
Solution:
we can achieve this in the following way
Step 1: Remove the Enforce relationship behavior
Step 2 : Delete the lookup column from the indexed column
But we can do the above step for one or two lists, my scenario, we have more than 25 lists, so we can not go this way. So I planned to do this from PowerShell. The following script i have written to finish this task.
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://chesgh201tw1v:1000");
#Open you web
$OpenWeb = $SpSite.OpenWeb();
#Open Your List
$List = $OpenWeb.Lists["Child"];
$column = $list.Fields["LookupField"]
$column.RelationshipDeleteBehavior = "None"
$column.Indexed = $false
$column.Update()
$column.AllowMultipleValues = $true
$column.Update()
$OpenWeb.Dispose();
$SPSite.Dispose()
I used this logic to remove the Enforce relationship behavior and delete the column from indexed column and set the AllowMultiple Values option for the lookup field.
Hope this help someone
Recently I have come across an issue where I needed to use PowerShell to update a particular field options. Moreover the field is a Lookup field. Our problem is that, we have more number of related lists in our application, where we are lookup the parent list item id in the child list item. So security reason we have set "Restrict Delete" in the Enforce Relationship behavior for the Lookup field. At this point we have set the lookup for a single field. (So we have not allowed Multiple lookup value).
Unfortunately we got a situation for multiple selection in the lookup field. By default in SharePoint 2010, Enforce relationship behavior will not available if we allow to select multiple values for the lookup field.
The above snapshot describes the default behavior of the lookup column with Allow multiple values. My current scenario also is the same, i need to enable the Allow multiple values for the lookup field.
Problem Definition:
When set Enforce relationship behavior for the lookup field, the column must be indexed. So the column which we have given restrict delete was indexed and now i am not able to enable Allow multiple values option,
Solution:
we can achieve this in the following way
Step 1: Remove the Enforce relationship behavior
Step 2 : Delete the lookup column from the indexed column
But we can do the above step for one or two lists, my scenario, we have more than 25 lists, so we can not go this way. So I planned to do this from PowerShell. The following script i have written to finish this task.
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://chesgh201tw1v:1000");
#Open you web
$OpenWeb = $SpSite.OpenWeb();
#Open Your List
$List = $OpenWeb.Lists["Child"];
$column = $list.Fields["LookupField"]
$column.RelationshipDeleteBehavior = "None"
$column.Indexed = $false
$column.Update()
$column.AllowMultipleValues = $true
$column.Update()
$OpenWeb.Dispose();
$SPSite.Dispose()
I used this logic to remove the Enforce relationship behavior and delete the column from indexed column and set the AllowMultiple Values option for the lookup field.
Hope this help someone
No comments:
Post a Comment