Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. xrm. SDK. query;
Using Microsoft. CRM. SDK. messages;
/// <Summary>
/// Invoice
/// </Summary>
Public class invoicehelper
{
Public static readonly string entityname = "invoice ";
Public guid invoiceid = guid. empty;
Public iorganizationservice service;
/// <Summary>
/// Create an invoice
/// </Summary>
Public void create (guid accountid)
{
Entity en = new entity () {logicalname = entityname, id = accountid };
En ["name"] = "invoice test ";
En ["accountid"] = new entityreference () {logicalname = "Account", id = accountid };
Invoiceid = service. Create (en );
}
/// <Summary>
/// Assign the invoice 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 = invoiceid };
Request. assignee = assignee;
Assignresponse response = (assignresponse) service. Execute (request );
}
/// <Summary>
/// Lock the unit price of the product in the specified invoice
/// </Summary>
Public void lockinvoicepricing ()
{
Lockinvoicepricingrequest request = new lockinvoicepricingrequest ();
Request. invoiceid = invoiceid;
Lockinvoicepricingresponse response = (lockinvoicepricingresponse) service. Execute (request );
}
/// <Summary>
/// Unlock the unit price of the product in the specified invoice
/// </Summary>
Public void unlockinvoicepricing ()
{
Unlockinvoicepricingrequest request = new unlockinvoicepricingrequest ();
Request. invoiceid = invoiceid;
Unlockinvoicepricingresponse response = (unlockinvoicepricingresponse) service. Execute (request );
}
/// <Summary>
/// Cancel all access permissions of the specified security subject (user or Team) on the invoice
/// </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 = invoiceid };
Request. revokee = revokee;
Revokeaccessresponse response = (revokeaccessresponse) service. Execute (request );
}
/// <Summary>
/// Delete the invoice
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, invoiceid );
}
}
CRM operation invoice entity