Search This Blog

Showing posts with label Single or multi Select. Show all posts
Showing posts with label Single or multi Select. Show all posts

Monday, April 24, 2017

How to check Lookup Field is a single or multi select programmatically using CSOM?

//The below Method is used to find the lookup field is a single or multi select

 public static bool AllowMultipleValues(ClientContext clientContext, List oList, string columnInternalName)
        {
            bool IsMultipleValues = false;
            try
            {
                if (oList != null)
                {
                    Field oField = oList.Fields.GetByInternalNameOrTitle(columnInternalName);
                    if (oField != null)
                    {
                        var lookupField = clientContext.CastTo<FieldLookup>(oField);
                        clientContext.Load(lookupField, x => x.AllowMultipleValues);
                        clientContext.ExecuteQuery();
                        IsMultipleValues = lookupField.AllowMultipleValues;
                        return IsMultipleValues;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogException(ex);
            }
            return IsMultipleValues;
        }