Skip to content
Amal Hashim
All posts
Snippet

SharePoint - Updating External Lookup Field

Update a Business Connectivity Services external lookup field on a list item using SPBusinessDataField and EntityInstanceIdEncoder.

1 min read#C##SharePoint#SharePoint 2010

Updating an external lookup (business data) field is a bit different from updating other lookup fields. This snippet shows how.

csharp
SPBusinessDataField dataField = item.Fields["Field Display Name"] as SPBusinessDataField;
item[dataField.RelatedField] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { NEWVALUE });
item["Field_x0020_Internal_x0020_Name"] = newCRMNumber;
  • item is the list item you are modifying.
  • item.Fields["Field Display Name"] needs the display name of the external field.
  • dataField.RelatedField is the hidden field that stores the encoded entity identifier.
  • The last line sets the visible column, using its internal name.

Call item.Update() afterwards to save the change.