Sample code for TargetCompoundSalesOrder and CompoundCreate Message

Just a sample code on how we can use the above classes

// retrieve the sales order class
TargetRetrieveSalesOrder targetSalesOrder =
 new TargetRetrieveSalesOrder();
targetSalesOrder.EntityId =
new Guid("guid");
RetrieveRequest myRReq = new RetrieveRequest();
myRReq.ColumnSet = new AllColumns();
myRReq.Target = targetSalesOrder;
RetrieveResponse myRRes = (RetrieveResponse)service.Execute(myRReq);
salesorder mySalesOrder =(salesorder)myRRes.BusinessEntity;
// setting guid to null else duplicate key error
mySalesOrder.salesorderid = null;
// retrieve all the sales order detail for the sales order
ConditionExpression expression = new ConditionExpression();
expression.AttributeName = "salesorderid";
expression.Operator = ConditionOperator.Equal;
expression.Values =
 new string[] { "guid" };
FilterExpression expression2 = new FilterExpression();
expression2.FilterOperator = LogicalOperator.And;
expression2.Conditions = new ConditionExpression[] { expression };
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.salesorderdetail.ToString();
query.ColumnSet = new AllColumns();
query.Criteria = expression2;
BusinessEntityCollection entitys = service.RetrieveMultiple(query);
salesorderdetail[] salesDetail=
new salesorderdetail[entitys.BusinessEntities.Length];
int i = 0;
foreach(BusinessEntity be in entitys.BusinessEntities)
{
salesDetail[i] =(salesorderdetail) be;
salesDetail[i].salesorderdetailid = null;
i++;
}
// initialize and set properties for TargetCompoundSalesOrder class
TargetCompoundSalesOrder tcSalesOrder =
new TargetCompoundSalesOrder();
tcSalesOrder.SalesOrder = mySalesOrder;
tcSalesOrder.SalesOrderDetails = salesDetail;
// use CompoundCreateRequest class
CompoundCreateRequest ccReq = new CompoundCreateRequest();
ccReq.Target = tcSalesOrder;
CompoundCreateResponse ccRes =
(CompoundCreateResponse)service.Execute(ccReq);

 

Bye..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Sample code for TargetCompoundSalesOrder and CompoundCreate Message”

Share your thoughts

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