2
votes

I'm trying to find metadata about the length of fields in MS Dynamics CRM 4.0 - does anyone know if/where this information is available from the metadata services? I tried looking on the AttributeMetadata class, but can't find anything there. Yet, the field length does show up in MS's metadata browser, so it must be accessible somehow.

2

2 Answers

3
votes

If you know the attribute is a string or ntext attribute, you can cast the AttributeMetadata object over to a StringAttributeMetadata object, and that will have the maximum length of those fields.

1
votes

Thanx @Matt worked like a charm. I used it as below:

StringAttributeMetadata stringAttributeMetadata = (StringAttributeMetadata)attributeMetadata;
recordToBeUpdated[recordFieldLogicalName] = recordFieldValue.Length < stringAttributeMetadata.MaxLength.Value ?  recordFieldValue : recordFieldValue.Substring(0,stringAttributeMetadata.MaxLength.Value - 1);