Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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