Skip to content

Instantly share code, notes, and snippets.

@Niels-V
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Niels-V/4e5d8ecaa239def44ccf to your computer and use it in GitHub Desktop.
Save Niels-V/4e5d8ecaa239def44ccf to your computer and use it in GitHub Desktop.
Provision additional lookup fields with CSOM
private void AddDependantLookup(List parentList, List targetList, Guid lookupFieldId, Field primaryLookupField, string displayName)
{
Field toField = parentList.Fields.GetById(lookupFieldId);
_clientContext.Load(toField);
_clientContext.Load(targetList);
_clientContext.ExecuteQuery();
Field dependantField = targetList.Fields.AddDependentLookup(displayName, primaryLookupField,
toField.StaticName);
FieldLookup dependantFieldLookup = _clientContext.CastTo<FieldLookup>(dependantField);
dependantFieldLookup.LookupField = toField.StaticName;
dependantField.UpdateAndPushChanges(true);
_clientContext.Load(dependantField);
_clientContext.ExecuteQuery();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment