2

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.

Badjer
  • 820
  • 2
  • 9
  • 16

2 Answers2

3

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.

Matt
  • 4,656
  • 1
  • 22
  • 32
1

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);