Last active
August 29, 2015 14:24
-
-
Save Niels-V/4e5d8ecaa239def44ccf to your computer and use it in GitHub Desktop.
Provision additional lookup fields with CSOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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