Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. xrm. SDK. query;
Using Microsoft. CRM. SDK. messages;
/// <Summary>
/// Sales order
/// </Summary>
Public class soleorderhelper
{
Public static readonly string entityname = "salesorder ";
Public guid soleorderid = guid. empty;
Public iorganizationservice service;
/// <Summary>
/// Create a sales order
/// </Summary>
Public void create (guid accountid)
{
Entity en = new entity () {logicalname = entityname, id = accountid };
En ["name"] = "sales order test ";
En ["accountid"] = new entityreference () {logicalname = "Account", id = accountid };
Soleorderid = service. Create (en );
}
/// <Summary>
/// Assign the sales order to another user or team
/// </Summary>
/// <Param name = "assignee"> User or team reference </param>
Public void assign (entityreference assignee)
{
Assignrequest request = new assignrequest ();
Request. Target = new entityreference () {logicalname = entityname, id = soleorderid };
Request. assignee = assignee;
Assignresponse response = (assignresponse) service. Execute (request );
}
/// <Summary>
/// Cancel the sales order
/// </Summary>
/// <Param name = "status"> canceled status </param>
Public void cancelsalesorder (INT status)
{
Cancelsalesorderrequest request = new cancelsalesorderrequest ();
Request. orderclose = new entity () {logicalname = entityname, id = soleorderid };
Request. Status = new optionsetvalue (Status );
Cancelsalesorderresponse response = (cancelsalesorderresponse) service. Execute (request );
}
/// <Summary>
/// Convert a sales order to an invoice
/// </Summary>
Public void convertsalesordertoinvoice ()
{
Convertsalesordertoinvoicerequest request = new convertsalesordertoinvoicerequest ();
Request. salesorderid = soleorderid;
Request. columnset = new columnset ("name", "accountid ");
Convertsalesordertoinvoiceresponse response = (convertsalesordertoinvoiceresponse) service. Execute (request );
Entity invoiceen = response. entity;
}
/// <Summary>
/// Complete the sales order
/// </Summary>
/// <Param name = "status"> completed status </param>
Public void fulfillsalesorder (INT status)
{
Fulfillsalesorderrequest request = new fulfillsalesorderrequest ();
Request. orderclose = new entity () {logicalname = entityname, id = soleorderid };
Request. Status = new optionsetvalue (Status );
Fulfillsalesorderresponse response = (fulfillsalesorderresponse) service. Execute (request );
}
/// <Summary>
/// Retrieve the product group of the sales order from the specified business opportunity
/// </Summary>
/// <Param name = "opportunityid"> business opportunity id </param>
Public void getsalesorderproductsfromopportunity (guid opportunityid)
{
Getsalesorderproductsfromopportunityrequest request = new getsalesorderproductsfromopportunityrequest ();
Request. opportunityid = opportunityid;
Request. salesorderid = soleorderid;
Getsalesorderproductsfromopportunityresponse response =
(Getsalesorderproductsfromopportunityresponse) service. Execute (request );
}
/// <Summary>
/// Lock sales order Pricing
/// </Summary>
Public void locksalesorderpricing ()
{
Locksalesorderpricingrequest request = new locksalesorderpricingrequest ();
Request. salesorderid = soleorderid;
Locksalesorderpricingresponse response = (locksalesorderpricingresponse) service. Execute (request );
}
/// <Summary>
/// Unlock the unit price of the product in the specified sales order (Order)
/// </Summary>
Public void unlocksalesorderpricing ()
{
Unlocksalesorderpricingrequest request = new unlocksalesorderpricingrequest ();
Request. salesorderid = soleorderid;
Unlocksalesorderpricingresponse response = (unlocksalesorderpricingresponse) service. Execute (request );
}
/// <Summary>
/// Cancel all access permissions of the specified security subject (user or Team) to the sales order
/// </Summary>
/// <Param name = "revokee"> User or team reference </param>
Public void revokeaccess (entityreference revokee)
{
Revokeaccessrequest request = new revokeaccessrequest ();
Request. Target = new entityreference () {logicalname = entityname, id = soleorderid };
Request. revokee = revokee;
Revokeaccessresponse response = (revokeaccessresponse) service. Execute (request );
}
/// <Summary>
/// Delete the sales order
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, soleorderid );
}
}
CRM operation sales order entity