This documentation is archived and is not being maintained.

CompoundCreate Message (CrmService)

Forefront
banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online and offline

Creates a compound entity (salesorder, invoice, quote, or duplicate rule) and its related entity (salesorderdetail, invoicedetail, quotedetail, or duplicaterulecondition).

The relevant classes are specified in the following table.

TypeClass
RequestCompoundCreateRequest
ResponseCompoundCreateResponse
TargetTargetCompound
EntitySee the following table.

The following table shows the entities and target classes for this message.

EntityTarget Class
DynamicEntityTargetCompoundDynamic
duplicateruleTargetCompoundDuplicateRule
invoiceTargetCompoundInvoice
quoteTargetCompoundQuote
salesorderTargetCompoundSalesOrder

Remarks

To use this message, pass an instance of the CompoundCreateRequest class as the request parameter in the Execute method.

To perform this action, the caller must have access rights on the entity instances specified in the request class. For a list of required privileges, see CompoundCreate Privileges.

Example

This sample shows how to create a sales order object and its associated sales order details object.

[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
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;

// Create the sales order object.
salesorder salesorder = new salesorder();

// Set the properties of the sales order object.
salesorder.name = "Test Order";
salesorder.customerid = new Customer();
salesorder.customerid.Value = accountCreated.id;
salesorder.customerid.type = EntityName.account.ToString();

// Create the sales order detail associated with the sales order.
salesorderdetail salesorderdetail = new salesorderdetail();

// Set the properties of the sales order detail object.
salesorderdetail.description = "Test";
salesorderdetail.owninguser = new UniqueIdentifier();
salesorderdetail.owninguser.Value =   user.UserId;

// Create the target object for the request.
TargetCompoundSalesOrder target = new TargetCompoundSalesOrder();

// Set the properties of the target object.
target.SalesOrder = salesorder;
target.SalesOrderDetails = new salesorderdetail[1] {salesorderdetail};

// Create the request object.
CompoundCreateRequest create = new CompoundCreateRequest();

// Set the properties of the request object.
create.Target = target;

// Execute the request.
CompoundCreateResponse created = (CompoundCreateResponse) service.Execute(create);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the sales order object.
Dim salesorder As New salesorder()

' Set the properties of the sales order object.
salesorder.name = "Test Order"
salesorder.customerid = New Customer()
salesorder.customerid.Value = accountCreated.id
salesorder.customerid.type = EntityName.account.ToString()

' Create the sales order detail associated with the sales order.
Dim salesorderdetail As New salesorderdetail()

' Set the properties of the sales order details object.
salesorderdetail.description = "Test"
salesorderdetail.owninguser = New UniqueIdentifier()
salesorderdetail.owninguser.Value = user.UserId

' Create the target object for the request.
Dim target As New TargetCompoundSalesOrder()

' Set the properties of the target object.
target.SalesOrder = salesorder
target.SalesOrderDetails = New salesorderdetail(0) {salesorderdetail}

' Create the request object.
Dim create As New CompoundCreateRequest()

' Set the properties of the request object.
create.Target = target

' Execute the request.
Dim created As CompoundCreateResponse = CType(service.Execute(create), CompoundCreateResponse)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show: