Export (0) Print
Expand All

Using the DynamicEntity Class

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

There are a set of target classes that are designed to work at run time for any entity, including those that might not have been included in the Web Services Description Language (WSDL) file when you compiled your code. This is supported by the DynamicEntity class. These target classes are listed in the following table.

Class name
TargetCompoundDynamic
TargetCreateDynamic
TargetDeleteDynamic
TargetMergeDynamic
TargetOwnedDynamic
TargetQuantifyDynamic
TargetQueuedDynamic
TargetRelatedDynamic
TargetRemoveParent
TargetRetrieveDynamic
TargetRollupDynamic
TargetScheduleDynamic
TargetUpdateDynamic
TargetUpdateDynamic

Example

In this example, the account entity is used. This is a system entity but it might not have all the properties defined in the WSDL at the design time.

[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);

DynamicEntity myAccount = new DynamicEntity();
myAccount.Name = "account";

CrmBooleanProperty donotbulkemail = new CrmBooleanProperty();
donotbulkemail.Value = new CrmBoolean();
donotbulkemail.Value.Value = true;

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

CrmMoneyProperty creditlimit = new CrmMoneyProperty();
creditlimit.Value = new CrmMoney();
creditlimit.Value.Value = 20000;

myAccount.Properties = new Property[]
{
   CreateProperty("name", "Redmond Cycle"),
   CreateProperty("address1_city", "Redmond"),
   CreateProperty("address1_postalcode", "98052"),
   donotbulkemail,
   ownerid,
   creditlimit,
};

TargetCreateDynamic myTarget = new TargetCreateDynamic();
myTarget.Entity = myAccount;
CreateRequest create = new CreateRequest();
create.Target = myTarget;
CreateResponse myResponse = (CreateResponse)service.Execute(create);

// The CreateProperty helper method creates an instance of a StringProperty.
private StringProperty CreateProperty(string name, string value)
{
   StringProperty property = new StringProperty();
   property.Name = name;
   property.Value = value;
   return property;
}

See Also

Concepts

Reference

Other Resources


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft