CRM operation quote entity

Source: Internet
Author: User

Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. CRM. SDK. messages;
Using Microsoft. xrm. SDK. query;

/// <Summary>
/// Quote
/// </Summary>
Public class quotehelper
{
Public static readonly string entityname = "quote ";
Public guid quoteid = guid. empty;
Public iorganizationservice service;

/// <Summary>
/// Create a quote
/// </Summary>
Public void create (guid accountid)
{
Entity en = new entity () {logicalname = entityname };
En ["name"] = "Quote test ";
En ["accountid"] = new entityreference () {logicalname = "Account", id = accountid };
Quoteid = service. Create (en );
}

/// <Summary>
/// Create a quote and Its Related quote details
/// </Summary>
/// <Param name = "childen"> quote details </param>
Public void compoundcreate (entitycollection childen)
{
Compoundcreaterequest request = new compoundcreaterequest ();
Request. entity = new entity () {logicalname = entityname };
Request. childentities = childen;
Compoundcreateresponse response = (compoundcreateresponse) service. Execute (request );
Quoteid = response. ID;
}

/// <Summary>
/// Assign the quote 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 = quoteid };
Request. assignee = assignee;
Assignresponse response = (assignresponse) service. Execute (request );
}

/// <Summary>
/// Specify the end quote
/// </Summary>
/// <Param name = "status"> end state value </param>
Public void closequote (INT status)
{
Closequoterequest request = new closequoterequest ();
Request. quoteclose = new entity () {logicalname = entityname, id = quoteid };
Request. Status = new optionsetvalue (Status );
Closequoteresponse response = (closequoteresponse) service. Execute (request );
}

/// <Summary>
/// Convert a quote to a sales order
/// </Summary>
Public Entity convertquotetosalesorder ()
{
Convertquotetosalesorderrequest request = new convertquotetosalesorderrequest ();
Request. quoteid = quoteid;
Request. columnset = new Microsoft. xrm. SDK. query. columnset ("name", "accountid ");
Convertquotetosalesorderresponse response = (convertquotetosalesorderresponse) service. Execute (request );
// Sales order
Entity solrorderen = response. entity;
Return solrorderen;
}

/// <Summary>
/// Obtain a small number of product values for the object specified in the target value
/// </Summary>
/// <Param name = "productid"> product ID </param>
/// <Param name = "uomid"> unit ID </param>
Public int getquantitydecimal (guid productid, guid uomid)
{
Getquantitydecimalrequest request = new getquantitydecimalrequest ();
Request. Target = new entityreference () {logicalname = entityname, id = quoteid };
Request. productid = productid;
Request. uomid = uomid;
Getquantitydecimalresponse response = (getquantitydecimalresponse) service. Execute (request );
Return response. quantity;
}

/// <Summary>
/// Retrieve the product from the business opportunity and copy it to the quote
/// </Summary>
/// <Param name = "opportunityid"> business opportunity id </param>
Public void getquoteproductsfromopportunity (guid opportunityid)
{
Getquoteproductsfromopportunityrequest request = new getquoteproductsfromopportunityrequest ();
Request. opportunityid = opportunityid;
Request. quoteid = quoteid;
Getquoteproductsfromopportunityresponse response =
(Getquoteproductsfromopportunityresponse) service. Execute (request );
}

/// <Summary>
/// Share the quotation sheet with other security subjects (users or teams)
/// </Summary>
/// <Param name = "accessmask"> access permission </param>
/// <Param name = "principal"> User or team reference </param>
Public void grantaccessrequest (accessrights accessmask, entityreference principal)
{
Grantaccessrequest request = new grantaccessrequest ();
Request. Target = new entityreference () {logicalname = entityname, id = quoteid };
Request. principalaccess = new principalaccess () {accessmask = accessmask, Principal = Principal };
Grantaccessresponse response = (grantaccessresponse) service. Execute (request );
}

/// <Summary>
/// Set the quote status to "draft"
/// </Summary>
Public void revisequote ()
{
Revisequoterequest request = new revisequoterequest ();
Request. quoteid = quoteid;
Request. columnset = new Microsoft. xrm. SDK. query. columnset ("name", "accountid ");
Revisequoteresponse response = (revisequoteresponse) service. Execute (request );
// Quote of draft status
Entity quoteen = response. entity;
}

/// <Summary>
/// Summarize or retrieve all quotations related to the specified record (customer or contact)
/// </Summary>
/// <Param name = "target"> customer or contact reference </param>
/// <Param name = "query"> query condition </param>
/// <Param name = "rolluptype"> association type </param>
Public void rollup (entityreference target, querybase query, rolluptype)
{
Rolluprequest request = new rolluprequest ();
Request. Target = target;
Request. query = query;
Request. rolluptype = rolluptype;
Rollupresponse response = (rollupresponse) service. Execute (request );
Entitycollection = response. entitycollection;
}

/// <Summary>
/// Delete the quote
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, quoteid );
}

}

CRM operation quote entity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.