CRM operation sales contract entity

Source: Internet
Author: User

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

/// <Summary>
/// Sales Contract
/// </Summary>
Public class contracthelper
{
Public static readonly string entityname = "contract ";
Public guid contractid = guid. empty;
Public iorganizationservice service;

/// <Summary>
/// Create a sales contract
/// </Summary>
Public void create ()
{
Entity en = new entity () {logicalname = entityname };
En ["title"] = "Sales Contract test ";
Contractid = service. Create (en );
}

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

/// <Summary>
/// Cancel the contract
/// </Summary>
/// <Param name = "status"> canceled status </param>
Public void cancelcontract (INT status)
{
Cancelcontractrequest request = new cancelcontractrequest ();
Request. contractid = contractid;
Request. canceldate = datetime. now;
Request. Status = new optionsetvalue (Status );
Cancelcontractresponse response = (cancelcontractresponse) service. Execute (request );
}

/// <Summary>
/// Copy the contract
/// </Summary>
Public void clonecontract ()
{
Clonecontractrequest request = new clonecontractrequest ();
Request. contractid = contractid;
Request. includecanceledlines = true;
Clonecontractresponse response = (clonecontractresponse) service. Execute (request );
// Sales Contract
Entity contracten = response. entity;
}

/// <Summary>
/// Renew the contract
/// </Summary>
Public void renewcontract ()
{
Renewcontractrequest request = new renewcontractrequest ();
Request. contractid = contractid;
Request. includecanceledlines = true;
// Contract status
Request. Status = 0;
Renewcontractresponse response = (renewcontractresponse) service. Execute (request );
// Sales Contract
Entity contracten = response. entity;
}

/// <Summary>
/// Share the sales contract with other security entities (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 = contractid };
Request. principalaccess = new principalaccess () {accessmask = accessmask, Principal = Principal };
Grantaccessresponse response = (grantaccessresponse) service. Execute (request );
}

/// <Summary>
/// Delete all access permissions of the specified security subject (user or Team) to the sales contract
/// </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 = contractid };
Request. revokee = revokee;
Revokeaccessresponse response = (revokeaccessresponse) service. Execute (request );
}

/// <Summary>
/// Delete the Sales Contract
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, contractid );
}
}

CRM operation sales contract 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.