No me hago responsable si copiaste mal algún código que sale en las páginas de este sitio.
Ojalá sea de ayuda para más de alguno este sitio.
Se agradece si deja algún comentario.

jueves, 2 de diciembre de 2010

Hide Columns in SharePoint New, Edit and Disp Forms: Poweshell

Ref: http://howtosharepoint.blogspot.com/2010/11/hide-columns-in-sharepoint-new-edit-and.html

Hide Columns in SharePoint New, Edit and Disp Forms: Powershell


So here is the scenario, you have a issue tracking list and if you only want to introduce certain hidden columns on your New and Disp forms but not your Edit form as an example. You can have any combination for these requirements.
Since the issues are logged by the QA or end-user, we want to hide the Assigned To, Due Date, Priority and Impact from the new form. We want the user editing, typically the dev team lead, to assign these values.

There are several ways you can achieve this.. choose the best that fits your need... or comfortable with.

1. PowerShell
2. Programmatically
3. Custom Forms (SharePoint Designer)
4. ContentTypes
5. jQuery

Using Powershell

  • First we need to get the id of the fields to be hidden. A very important tool in your armor is a free tool called SharePoint Manager 2010.
  • Navigate to your Web-App > Site Collection > Site > List > Fields and get the ids of the fields you want to hide
  • Next we will use another important free tool PowerGUI and write the following powershell script
  • #$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    #if ($snapin -eq $null) {
    #Write-Host "Loading SharePoint Powershell Snapin"
    #Add-PSSnapin "Microsoft.SharePoint.Powershell"
    #}
    
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    
    $WebUrl = "http://sp2010vmc002/hidecoldemo"
    Write-Host "Opening Web" $WebUrl
    $web = Get-SPWeb $WebUrl
    
    ####### Issue Tracker List ######
    $list = $web.Lists["IssueTracker1"];
    
    #Assigned To
    $FieldGuid = New-Object System.Guid("53101f38-dd2e-458c-b245-0c236cc13d1a");
    $Field = $list.Fields[$FieldGuid];
    
    $Field.ShowInNewForm = $false;
    $Field.ShowInDisplayForm = $true;
    $Field.ShowInEditForm = $true;
    
    $Field.Update();
    $list.Update();
    
    #Due Date
    $FieldGuid = New-Object System.Guid("cd21b4c2-6841-4f9e-a23a-738a65f99889");
    $Field = $list.Fields[$FieldGuid];
    
    $Field.ShowInNewForm = $false;
    $Field.ShowInDisplayForm = $true;
    $Field.ShowInEditForm = $true;
    
    $Field.Update();
    $list.Update();
    
    #Similarly for Impact and Propority..
    
    $Web.Dispose();  
    
  • The resultant new form will look like this




Ref:
http://blog.qumsieh.ca/2010/02/16/hide-columns-in-sharepoint-new-edit-and-disp-forms/

No hay comentarios:

Publicar un comentario