Answered by:
retrieve the datatypes of CRM entity attributes

Question
-
Hi Friends,
I want to retrieve the datatypes of CRM entity attributes using CRM metadataservice..How it possible?..pls help me..I had retrieved the names of CRM entity attributes using CRM metadataservice.
Thursday, July 15, 2010 7:22 AM
Answers
-
Hi,
you can use something like as below
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest(); attributeRequest.EntityLogicalName = EntityName.account.ToString(); attributeRequest.LogicalName = "accountnumber"; attributeRequest.RetrieveAsIfPublished = false; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)metadataService.Execute(attributeRequest); string DataType = attributeResponse.AttributeMetadata.AttributeType.Value.ToString();
Mahain- Marked as answer by Hari nvp Monday, July 19, 2010 10:44 AM
Monday, July 19, 2010 7:17 AMModerator
All replies
-
Hey,
you can use AttributeType property to get data type of crm attribute that you have fetched like below
for example if you are getting individual attribute you should be able to get it's datatype using below code
Response.AttributeMetadata.AttributeType.Value
Let us know if you need any other help !!!
Mahain- Proposed as answer by HIMBAPModerator Thursday, July 15, 2010 8:11 AM
Thursday, July 15, 2010 8:10 AMModerator -
Thanks Mahain,
Pls explain me..If I want to store the datatype of 'account number' attribute of 'account' entity in a string, how it is possible?..pls help me
Monday, July 19, 2010 6:57 AM -
And,
AttributeMetadata.AttributeType is not recognized..
Monday, July 19, 2010 7:16 AM -
Hi,
you can use something like as below
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest(); attributeRequest.EntityLogicalName = EntityName.account.ToString(); attributeRequest.LogicalName = "accountnumber"; attributeRequest.RetrieveAsIfPublished = false; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)metadataService.Execute(attributeRequest); string DataType = attributeResponse.AttributeMetadata.AttributeType.Value.ToString();
Mahain- Marked as answer by Hari nvp Monday, July 19, 2010 10:44 AM
Monday, July 19, 2010 7:17 AMModerator -
Hi,
I think you want to retrieve the entity attributes datatype: Below is the code which return the Entity Metadata:
private RetrieveEntityResponse RetrieveEntityMetadata(string strEntityName)
{
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = this._organization;
MetadataService service = new MetadataService();
service.CrmAuthenticationTokenValue = token;
service.Credentials = new NetworkCredential(this._userName, this._password, this._domain);
service.Url = "http://" + this._hostName + "/MSCRMServices/2007/MetadataService.asmx";
RetrieveEntityRequest request = new RetrieveEntityRequest();
request.EntityItems = EntityItems.All;
request.LogicalName = strEntityName.ToLower(); //this._entityName.ToLower();
return (service.Execute(request) as RetrieveEntityResponse);
}Call the above fucntion as below:
foreach (AttributeMetadata metadata2 in RetrieveEntityMetadata(strEntityName).EntityMetadata.Attributes)
{
// will display the attribute name and its datatype: Perform the operations depending on the attribute name by using CASE statement
string logicalName = metadata2.LogicalName;
string datatype = metadata2.AttributeType.Value.ToString();
}Hope this will help you to resolve the issue.
Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM ConsultantMonday, July 19, 2010 9:10 AM