views:

5493

answers:

5

I would like to display certain meta data fields in the edit form based on the value of a fields.

Example: Users upload a document to the Doclib to be approved by there manager. They are allowed to change the meta data Name,Case No, Location until the item is approved by the manager. Once the item is approved I would like to set Name and Case Number to read only.

What is the best way to meet this requirement?

If approved = yes set Name and Case No = Read only Else do nothing.

+1  A: 

This can be easily solved with SharePoint Designer.

  • You will need to modify EditForm.aspx for your list
  • Hide the default ListFormWebPart (Do not delete it!)
  • Insert custom edit item form (more details...)

Custom form will look exactly the same as the default one, but you will be able to customize it with SharePoint Designer. The code below can be used for default WSS Issues list. It will show Issue title as read-only when Issue Status = Closed.

<xsl:choose>
    <xsl:when test="@Status != 'Closed'">
     <SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Title" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
     <SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="Edit"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="@Title"></xsl:value-of>
    </xsl:otherwise>
</xsl:choose>

You can apply the same logic for your custom lists or/and requirements.

As usual, you might run to some additional problems. I was not able to get the value of @_ModerationStatus in Data View Web Part. I do not know the exact reason...

Here is a simple workaround:

  1. Create a Column in your Document Library
  2. Create a new in workflow SharePoint Designer.

It should fire when item is changed and copy the value of approval status to newly created column.

You can use the custom column for conditional formatting.

Toni Frankola
Be aware that this will only work in the page customised as outlined above. Users will be able to edit these fields through other aspects of the SharePoint UI - specifically the Datasheet editing (Actions > Edit in Datasheet when viewing a list), also by connecting up Access 2007 to the list in question. Permissions can be set to list items, and lists, but not broken down to particular columns, though there are third party solutions from companies like Bamboo Solutions that attempt to provide this functionality.
Harv
A: 

I have tried this method for about 5 hours. I believed this may be different for ModerationStatus. Might require something special

print("<xsl:choose>
<xsl:when test="@_ModerationStatus != '0;#approved'">      
<SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="Edit" FieldName="Test_x0020_Session" __designer:bind="{ddwrt:DataBind('u',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Test_x0020_Session')}"/>
<SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="Test_x0020_Session" ControlMode="Edit"/>      
</xsl:when>
<xsl:otherwise>
     <xsl:value-of select="@Test_x0020_Session"></xsl:value-of>
</xsl:otherwise>

");

I can get it to work with the other fields but not ModerationStatus. I have also tried changing it to !='0' and !='Approved' and '0;#Approved'. Is there something I am doing wrong?

Seems like its stuck on 0;#Approved

Jordan Johnson
Are you using a default list or something custom? In case you are using custom, send it to me as template to [email protected]?
Toni Frankola
A: 

Follow Toni's comments but for your *ModerationStatus field use following XSLT function:

<xsl:when test="not(starts-with(@_ModerationStatus,'0'))">
Bulat
A: 

Thanks to Toni this really helped solved my problem.

Jordan Johnson
A: 

Hi! I'd like to use this example to hide or make read-only certain fields based on the user's role (eg. user belongs to certain SharePint group). Can anybody help me out and write some example code, please?

Rob