locked
Setting ShowInDisplayForm, ShowInEditForm, ShowInNewForm properties with powershell RRS feed

  • Question

  • I am trying to set ShowInDisplayForm, ShowInEditForm, ShowInNewForm properties of the filed in a custom list using powershell. This looks straightforward and powershell code is quite simple:

    #get the site
    $site = new-object Microsoft.SharePoint.SPSite("http://sv42104bosv271")
    $web = $site.OpenWeb()
    #get the list
    $list = $web.Lists["MyList"]
    #set col1
    $field = $list.Fields["col1"]
    $field.ShowInNewForm = "false"
    $field.ShowInEditForm = "false"
    $field.ShowInDisplayForm = "false"
    $field.Update()
    #set col2
    $field = $list.Fields["col2"]
    $field.ShowInNewForm = "false"
    $field.ShowInEditForm = "false"
    $field.ShowInDisplayForm = "false"
    $field.Update()
    #update & dispose
    $list.Update()
    $web.Dispose()
    $site.Dispose()

    This runs without any error messages in “SharePoint 2010 Management Shell”, but the expected behavior is not being applied. I have also done an iisreset, but still col1 and col2 remain visible in all 3 forms...

    Has anyone have a suggestion on this?

    Thanks in advance!

    Tofig

    Thursday, December 2, 2010 4:11 PM

Answers

  • Hi,

    i use I just use 0 and 1 there are some information about this avaliable on my blog  too.

    To get this done using this.

    # First load SharePoint Core Assembly
    [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    
    $url = "http://myserver:Port";
    $list = "List";
    $fieldname = "NewColumn";
     
    $contextSite = New-Object Microsoft.SharePoint.SPSite($url);
    $contextWeb = $contextSite.OpenWeb();
    $list = $contextWeb.Lists.TryGetList($list);
    
    $field = $list.Fields[$fieldname];
    
    # Controls Field in Edit Form
    $field.ShowInEditForm = 1;
    # Controls Field in New Form
    $field.ShowInNewForm = 0;
    # Controls Field in New Form
    $field.ShowInDisplayForm = 1;
    
    # Hides fields from list settings
    $field.ShowInListSettings = 1;
    
    # Hides fields from version history
    $field.ShowInVersionHistory = 1;
    
    # Hides fields form selection in views
    $field.ShowInViewForms = 1;
    
    # Don't forget to update this field
    $field.Update();
    $contextWeb.Dispose();
    $contextSite.Dispose();
    


    As we discuss in our other post ;) http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/6e94d1e5-6a42-468c-8315-efb1b5cd4c4c/#9cc5b412-ae9c-4519-b798-85d051a986ec

    Hope this helps.

    Kind regards Stefan


    http://www.n8d.at/blog
    twitter: n8design
    MCTS - SharePoint / WSS Configuration and Development
    • Marked as answer by Tofig Friday, December 3, 2010 8:26 AM
    Thursday, December 2, 2010 9:34 PM
  • thank you!

    my problem was that I used "true"/"false" instead of 1/0
    I just changed that in my scirpt and that worked fine

     

    • Marked as answer by Tofig Friday, December 3, 2010 8:26 AM
    Friday, December 3, 2010 8:25 AM
  • I know you already solved this, so this is just a heads up. If you want to use true/false instead of 0/1 the actual syntax is $true and $false. Not "true" and "false".

    You can read more about it here: http://blogs.msdn.com/b/powershell/archive/2006/12/24/boolean-values-and-operators.aspx


    http://www.aarebrot.net
    Facts are meaningless. You could use facts to prove anything that's even remotely true!
    • Marked as answer by Tofig Friday, December 3, 2010 1:50 PM
    Friday, December 3, 2010 1:39 PM

All replies

  • Hi,

    i use I just use 0 and 1 there are some information about this avaliable on my blog  too.

    To get this done using this.

    # First load SharePoint Core Assembly
    [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    
    $url = "http://myserver:Port";
    $list = "List";
    $fieldname = "NewColumn";
     
    $contextSite = New-Object Microsoft.SharePoint.SPSite($url);
    $contextWeb = $contextSite.OpenWeb();
    $list = $contextWeb.Lists.TryGetList($list);
    
    $field = $list.Fields[$fieldname];
    
    # Controls Field in Edit Form
    $field.ShowInEditForm = 1;
    # Controls Field in New Form
    $field.ShowInNewForm = 0;
    # Controls Field in New Form
    $field.ShowInDisplayForm = 1;
    
    # Hides fields from list settings
    $field.ShowInListSettings = 1;
    
    # Hides fields from version history
    $field.ShowInVersionHistory = 1;
    
    # Hides fields form selection in views
    $field.ShowInViewForms = 1;
    
    # Don't forget to update this field
    $field.Update();
    $contextWeb.Dispose();
    $contextSite.Dispose();
    


    As we discuss in our other post ;) http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/6e94d1e5-6a42-468c-8315-efb1b5cd4c4c/#9cc5b412-ae9c-4519-b798-85d051a986ec

    Hope this helps.

    Kind regards Stefan


    http://www.n8d.at/blog
    twitter: n8design
    MCTS - SharePoint / WSS Configuration and Development
    • Marked as answer by Tofig Friday, December 3, 2010 8:26 AM
    Thursday, December 2, 2010 9:34 PM
  • thank you!

    my problem was that I used "true"/"false" instead of 1/0
    I just changed that in my scirpt and that worked fine

     

    • Marked as answer by Tofig Friday, December 3, 2010 8:26 AM
    Friday, December 3, 2010 8:25 AM
  • I know you already solved this, so this is just a heads up. If you want to use true/false instead of 0/1 the actual syntax is $true and $false. Not "true" and "false".

    You can read more about it here: http://blogs.msdn.com/b/powershell/archive/2006/12/24/boolean-values-and-operators.aspx


    http://www.aarebrot.net
    Facts are meaningless. You could use facts to prove anything that's even remotely true!
    • Marked as answer by Tofig Friday, December 3, 2010 1:50 PM
    Friday, December 3, 2010 1:39 PM
  • to Frode:

     

    thank you!

    Friday, December 3, 2010 1:50 PM
  • I have built a solution that will allow non-admin users show and hide fields in the same way powershell lets you.

    http://spc3.codeplex.com/wikipage?title=ShowHideFields

    Monday, January 10, 2011 1:18 AM
  • Acesse a url:http://social.microsoft.com/forums/pt-br/reportabug certamente encontrará subsídio com um vasto conteúdo, que poderá lhe ajudar, e a cessão de Faq da Microsoft.

    Siga-nos, sempre:

    http://www.amigosdaprontotel.com.br/seja_franqueado.php?indicacao=1652

    http://www.amigosdaprontotel.com.br/seja_franqueado.php?indicacao=2442

    http://www.amigosdaprontotel.com.br/seja_franqueado.php?indicacao=2554


    AmigosdaProntotel1652
    Friday, March 18, 2011 5:16 PM
  • update your site parameter and run below power shell code to  hide column 

    # replace these details (also consider using Get-Credential to enter password securely as script runs).. 
    $username = "abcd@xyz.com" 
    $password = "*****" 
    $url = "http://siteurl"

    $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force 

    # the path here may need to change if you used e.g. C:\Lib.. 
    Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
    Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 
    # note that you might need some other references (depending on what your script does) for example:
    Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll" 

    # connect/authenticate to SharePoint Online and get ClientContext object.. 
    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url) 
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 
    $clientContext.Credentials = $credentials 



     #$rootWeb = $clientContext.Web

      $list = $clientContext.Web.Lists.GetByTitle("TestList");
     $clientContext.Load($list)
     $clientContext.ExecuteQuery()

     $fields=$list.Fields
      $clientContext.Load($fields)
     $clientContext.ExecuteQuery()

     $field=$fields.GetByInternalNameOrTitle("Title");

     

    t

     #To display
     #$field.SetShowInDisplayForm(1)
      #$field.SetShowInEditForm(1)
    # $field.SetShowInNewForm(1)

     #to hide
      $field.SetShowInDisplayForm(0)
      $field.SetShowInEditForm(0)
     $field.SetShowInNewForm(0)


     $field.Update()

      $clientContext.Load($field)
     $clientContext.ExecuteQuery()

     
    Friday, July 7, 2017 10:18 AM