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