Export (0) Print
Expand All
2 out of 4 rated this helpful - Rate this topic

Using CRM Attribute Types

CRM 1.2
banner art

Microsoft CRM 3.0 contains a set of attribute type classes used to define the attributes for each entity. These classes are specified in the following table.

Class name Description
CrmBoolean Used for attributes of type Boolean.
CrmDateTime Used for attributes of type date/time.
CrmDecimal Used for attributes of type decimal.
CrmFloat Used for attributes of type float.
CrmMoney Used for attributes of type money.
CrmNumber Used for attributes of type number.
CrmReference Used for attributes that refer to another entity. You must set both the type and Value fields when setting an attribute of this type.
Customer Used for attributes that refer to a customer. This type is a subclass of CrmReference.
EntityNameReference Used for attributes that refer to the entity name.
Key Used for attributes that represent a primary key.
Lookup Used for attributes that refer to another entity . This type is a subclass of CrmReference.
Owner Used for attributes that refer to the owner of an entity. This type is a subclass of CrmReference.
Picklist Used for attributes of type picklist.
EntityNameStateInfo Used for attributes of type state, where EntityName is the name of the entity in camel case.
Status Used for attributes of type status.
uniqueidentifier Used for attributes that represent a GUID.

Examples

The following sample shows how to set the value of each data type.

// Set up the CRM service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

CrmBoolean boolean = new CrmBoolean();
boolean.Value = true;

CrmDateTime dateTime = new CrmDateTime();
dateTime.Value = "2006/5/27T17:00:00";

CrmDecimal dec = new CrmDecimal();
dec.Value = (decimal)10.1;

CrmFloat f = new CrmFloat();
f.Value = (float)10.1;

CrmMoney money = new CrmMoney();
money.Value = (decimal)10.00;

CrmNumber number = new CrmNumber();
number.Value = 10;

Lookup lookup = new Lookup();
lookup.Value = user.UserId;
lookup.type = EntityName.systemuser.ToString();

Owner owner = new Owner();
owner.type = EntityName.systemuser.ToString();
owner.Value = user.UserId;

Picklist list = new Picklist();
list.Value = 1;

Status status = new Status();
status.Value = 1;

EntityNameReference reference = new EntityNameReference();
reference.Value = EntityName.systemuser.ToString();

Key key = new Key();
key.Value = user.UserId;

Assigning Null Values

When you update an entity instance there is a mechanism in place to differentiate the absence of a value from a null value. To set an attribute value to null you must set both IsNull and IsNullSpecified to True. For attributes of type String, you must assign the value to String.Empty.

Example

The following code example shows how to create null instances of the various Microsoft CRM attribute types.

// Set up the CRM service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

CrmBoolean boolean = new CrmBoolean();
boolean.IsNull = true;
boolean.IsNullSpecified = true;

CrmDecimal dec = new CrmDecimal();
dec.IsNull = true;
dec.IsNullSpecified = true;

CrmFloat f = new CrmFloat();
f.IsNull = true;
f.IsNullSpecified = true;

CrmMoney money = new CrmMoney();
money.IsNull = true;
money.IsNullSpecified = true;

CrmNumber number = new CrmNumber();
number.IsNull = true;
number.IsNullSpecified = true;

Lookup lookup = new Lookup();
lookup.IsNull = true;
lookup.IsNullSpecified = true;

PickList list = new PickList();
list.IsNull = true;
list.IsNullSpecified = true;

Status status = new Status();
status.IsNull = true;
status.IsNullSpecified = true;

Owner owner = new Owner();
owner.IsNull = true;
owner.IsNullSpecified = true;

Related Topics

Dynamic Entity Classes

Helper Code for CRM Types


© 2007 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.