Search code examples
tridiontridion-2011

How to check if field allow multiple values using core service


Using core service how can we check if a field allow multiple values, below is the code I'm using to get the type of field:-

SchemaFieldsData fields = client.ReadSchemaFields(schemaTCMURI, true, new ReadOptions());

                foreach (var field in fields.MetadataFields)
                {
                    if (field is SingleLineTextFieldDefinitionData)
                    {
                        // some code
                    }
                    else if (field is MultiLineTextFieldDefinitionData)
                    {
                // this will check only if field is multiline not multi valued                        }

}

Please suggest.


Solution

  • You need to check the MinOccurs and MaxOccurs properties. If MinOccurs is 0 the field is optional, otherwise it's mandatory. If MaxOccurs is 1, the field is single-value. Otherwise it's multi-value.