Tuesday, July 29, 2014

Custom Edit List Form Modified By field is blank -

Custom Form Does Not Display “Created By” value


I was customizing a sharepoint list today and customer asked for a modification to the New and Edit forms for the list.  I was using Designer to accomplish the task and was able to get most of it working.  The customer had asked for a field on the edit form to show the Modified by field.  This is the standard canned field which is part of every list in SharePoint.  I thought no problem I just get the internal field name and use the <xsl:value-of select="@Editor"/>. 

Challenge:

Each time I would load the edit form the field would resolve to empty.  This made no sense and really drove me crazywhile I tried to understand the problem. 

Sample:
<tr>
      <td valign="top" class="ms-formlabel" width="190px">
       <H3 class="ms-standardheader">
        <nobr>Modified By</nobr>
       </H3>
     <!--Always Blank --/>
       <xsl:value-of select="@Editor" disable-output-escaping="yes"/>
      

      </td>
      <td valign="top" class="ms-formbody" width="400px">
       <SharePoint:FormField runat="server" id="ModifiedByID" ControlMode="New" FieldName="Editor" __designer:bind="{ddwrt:DataBind('u','ModifiedByID','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Editor')}"/>
       <SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="Editor" ControlMode="Edit"/>
      </td>
     </tr>

Solution:

It helped me to look at the entire form and pay close attention to the syntax for the FormField control.
This includes the attribute ControlMode.  This tells the form control what state it is currently in.  (New,Edit,Display)  The key mistake I had made was to set this controlmode attribute to New instead of Edit.Once I set the controlmode attribute to Edit the value began to be passed to the form and displayed.

Corrected:
<tr>
<td valign="top" class="ms-formlabel" width="190px">
<H3 class="ms-standardheader">
<nobr>Modified By</nobr>
</H3>
<!--Always Blank --/>
<xsl:value-of select="@Editor" disable-output-escaping="yes"/>


</td>
<td valign="top" class="ms-formbody" width="400px">
<SharePoint:FormField runat="server" id="ModifiedByID" ControlMode="Edit" FieldName="Editor" __designer:bind="{ddwrt:DataBind('u','ModifiedByID','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Editor')}"/>
<SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="Editor" ControlMode="Edit"/>
</td>
</tr>

No comments:

Post a Comment