1

The goal is to automatically fill a lookup value on a new item form, hidden from the user, based on a parameter value. Preferably without using JavaScript, since I am using a parameter passed from a web part, not a query string. I have followed several tutorials on this issue, but many utilize JavaScript solutions, and the ones that don't aren't working (they seem to be based on SharePoint 2010 or earlier).

Environment: Sharepoint Online, using Sharepoint Designer 2013. Internal name for Lookup Column is "NewColumn1."

Steps:

  • In SPD 2013, create a custom New Item Form for a custom list.
  • No designer view is present to click on and delete the lookup control, so the XSL template is edited like so:

Before:

<td width="400px" valign="top" class="ms-formbody">
    <SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="New" FieldName="NewColumn1" __designer:bind="{ddwrt:DataBind('i',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@NewColumn1')}"/>
    <SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="NewColumn1" ControlMode="New"/>
</td>

After:

<td width="400px" valign="top" class="ms-formbody">
    <asp:TextBox runat="server" id="ff12{$Pos}" FieldName="NewColumn1" Text="1" __designer:bind="{ddwrt:DataBind('i',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@NewColumn1')}" />
    <SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="NewColumn1" ControlMode="New"/>
</td>

This is, of course, a test with a hardcoded value to see if I can use the text box to submit the lookup value. The "1" is the ID of the parent item I'm testing.

Submitting the form results in a new item being created, but the lookup column is blank. Viewing the HTML source of the rendered page, it appears that the field id and name values are shorter than those of the rest of the form, although I'm not sure this is having an effect:

HTML of form field from the "before" template:

<td width="400px" valign="top" class="ms-formbody"><span dir="none"><select name="ctl00$ctl32$REDACTED_WEB_PART_ID$ff12_1$ctl00$Lookup" id="ctl00_ctl32_REDACTED_WEB_PART_ID_ff12_1_ctl00_Lookup" title="Jenzabar ID">
    <option selected="selected" value="0">(None)</option>
    <option value="2">111111</option>
    <option value="1">314189</option>
</select><br/></span></td></tr>

HTML of form field from the "after" template:

<td width="400px" valign="top" class="ms-formbody">
    <input name="ctl00$ctl32$REDACTED_WEB_PART_ID$ff121" type="text" value="1" id="ctl00_ctl32_REDACTED_WEB_PART_ID_ff121" FieldName="NewColumn1" />
</td>

It appears the id and name properties are being generated differently when the Sharepoint:FormField is replaced by the asp:TextBox after the ff12 part. Even in the "after" template, the rendered HTML of other text box fields (created by the default SharePoint:FormField) end with a tag like _ctl00_ctl00_TextField.

Any guidance is appreciated, as well as alternative solutions or even explanations for this behavior. I'm steering clear of JavaScript because this particular use case avoids the usage of query strings, and I don't know how to capture a parameter with JavaScript that doesn't come from a query string. I'm definitely a beginner with SharePoint, so simple solutions preferred, haha.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.