Changing Data Type of an attribute in CRM 3.0

Once i had a problem with simple nvarchar datatype in CRM . My client wanted to have it as integer so that he can sort it out correctly. Literally speaking , it is really head ache if you have existing data in an attribute and you want to change the data type. As it is not supported in CRM . Today, i was reading in crm news group , a guy was having more or less same problem. I thought to share my experience.

Problem = i have a field with format “Date and Time ” and i would like to move that data to another field , which is having “Date only” format.

Solution : Now i will retrieve all accounts and move the data from one field to another one and then i will be updating the accounts.

protected void Button4_Click1(object sender, EventArgs e)

{

CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
QueryExpression query = new QueryExpression();
query.EntityName = “account”;
ColumnSet columns = new ColumnSet(); columns.Attributes = new string[] { “accountid”, “name”, “new_lastupdated” };

query.ColumnSet = columns;
BusinessEntityCollection ret = service.RetrieveMultiple(query);

for (int i = 0; i < ret.BusinessEntities.Length; i++) {

account see = (account)ret.BusinessEntities[i];
see.new_hello = new CrmDateTime(); // new_hello is is having “date only” format see.new_hello.Value = see.new_lastupdated.date; // “lastupdated ” is having ” date and time” format
service.Update(see);

Label1.Text = “updated”;

}

Advertisements

0 Responses to “Changing Data Type of an attribute in CRM 3.0”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: