Export (0) Print
Expand All

Dynamic Entity Targets

CRM 1.2
banner art

There are a set of target classes that are designed to work at runtime for any entity, including those that may not have been included in the WSDL file when you compiled your code. For example, you are adding a menu item that opens a dialog allowing the user to select from a list of entities, including custom entities added after your code is deployed. These targets are listed in the following table.

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

Example

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

CrmService service = new CrmService();
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);

// Helper method
private StringProperty CreateProperty(string name, string value)
{
   StringProperty property = new StringProperty();
   property.Name = name;
   property.Value = value;
   return property;
}

Related Topics

Execute

Request and Response Classes

Using DynamicEntity


© 2007 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft