Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Sharepoint error when updating display name for a lookup column

$
0
0

Hi,

I have a small issue on my hands. Trying to update the display name of three lookup columns. Two of them works fine, the third gives me the following issue.

Invoke-Command : Exception calling "Update" with "1" argument(s): "/projekt/Lists/Projekt : <nativehr>0x80070057</nativehr><nativestack></nativestack>

"

At C:\Users\Administrator\Desktop\ChangeFieldName.ps1:22 char:19

+     Invoke-Command <<<<  $script

    + CategoryInfo          : NotSpecified: (:) [Invoke-Command], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException,Microsoft.PowerShell.Commands.InvokeCommandCommand

I'm not 100% sure but i think the error could be that someone has changed this particular column via the UI at some point.
Could that perhaps cause this kind of problems?

Anyway, here is a bit more background

  1. In the current solution we have 3 lookup columns at site collection level that all needs to change names.
  2. All 3 columns are included in 3 different content types
  3. All 3 columns points to the same list
  4. All 3 columns have the same display name(but different internal and static names)
    1. Don’t ask me why we have 3 columns with the same name that collects exactly the same values from the same list. I think the solution has evolved over the years ;-)
    2. Their internal name and static names are Program, ProgramPI and ProgramGlobal
  5. The column “Program” is only used within a list called “Orders” at site collection level
  6. The column “ProgramPI” is used within a list called “ProjectInfo” in subsites.
  7. The column “ProgramGlobal” is used within a list called “ProjectGlobal” at site collection level
  8. Changing the display name of the first two works fine(Program and ProgramPI). When changing the name of the third column ProgramGlobal, it does change the column name
    at site collection level but not within the list “ProjectGlobal” where it is used. That’s when we get our above error. It cannot push down changes to the list.

Here is the PowerShell command which generates the above error message.

As a little help, in the last section of the PowerShell code I’m invoking the function “using-culture” which in turn executes a script block. This is to make sure we change the
column name in Swedish. Within the script block we invoke the function SetFieldDisplayName.

#############START Powershell code################

if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )

{    

   Add-PsSnapin Microsoft.SharePoint.PowerShell

}

Function Using-Culture (

[System.Globalization.CultureInfo]$culture = (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),

[ScriptBlock]$script= (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"))

{

    $OldCulture = [Threading.Thread]::CurrentThread.CurrentCulture

    $OldUICulture = [Threading.Thread]::CurrentThread.CurrentUICulture

    trap

    {

        [Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture

        [Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture

    }

  

    [Threading.Thread]::CurrentThread.CurrentCulture = $culture

    [Threading.Thread]::CurrentThread.CurrentUICulture = $culture

    Invoke-Command $script

    [Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture

    [Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture

}

$scriptBlock =

{

    Function SetFieldDisplayName([string]$webUrl, [string]$fieldStaticName, [string]$fieldDisplayName)

    {

            #Fetch web object

            $site = Get-SPSite -Identity $webUrl;

            $web = $site.RootWeb;

           

         

            $field = $web.Fields.GetField($fieldStaticName)

           

            $field.Title = $fieldDisplayName              

            $field.Update($true) #Push down changes to lists

          

            $web.Dispose()

            $site.Dispose()       

    }

    $webUrl = "http://www.wingtip.com";

    $fieldDisplayName = "Unit";

    $fieldStaticName = "Program"; #Program

   
#SetFieldDisplayName $webUrl $fieldStaticName $fieldDisplayName

   

    $fieldStaticName = "ProgramPI" #ProgramPI

    #SetFieldDisplayName $webUrl $fieldStaticName $fieldDisplayName

    $fieldStaticName = "ProgramGlobal" #ProgramGlobal

    SetFieldDisplayName $webUrl $fieldStaticName $fieldDisplayName

}

using-culture sv-SE  $scriptBlock

#using-culture en-US  $scriptBlock

###############END Powershell code#####################

Br,
Peter


Peter


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>