CRM operation case entity

Source: Internet
Author: User

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

/// <Summary>
/// Case
/// </Summary>
Public class incidenthelper
{
Public static readonly string entityname = "incident ";
Public guid incidentid = guid. empty;
Public iorganizationservice service;

/// <Summary>
/// Create a case
/// </Summary>
Public void create ()
{
Entity en = new entity () {logicalname = entityname };
En ["name"] = "case test ";
Incidentid = service. Create (en );
}

/// <Summary>
/// Calculate the total time spent in the case
/// </Summary>
Public void calculatetotaltimeincident ()
{
Calculatetotaltimeincidentrequest request = new calculatetotaltimeincidentrequest ();
Request. incidentid = incidentid;
Calculatetotaltimeincidentresponse response = (calculatetotaltimeincidentresponse) service. Execute (request );
Long time = response. totaltime;
}

/// <Summary>
/// Set the case status to "ended"
/// </Summary>
/// <Param name = "status"> end status </param>
Public void closeincident (INT status)
{
Closeincidentrequest request = new closeincidentrequest ();
Request. incidentresolution = new entity () {logicalname = entityname, id = incidentid };
Request. Status = new optionsetvalue (Status );
Closeincidentresponse response = (closeincidentresponse) service. Execute (request );
}

/// <Summary>
/// Verify whether the case can be terminated at any time
/// </Summary>
/// <Param name = "state"> active, resolved, canceled </param>
/// <Param name = "status"> inprogress: 1, onhold: 2, waitingfordetails: 3, researching: 4 </param>
/// <Param name = "status"> problemsolved: 5, informationprovided: 1000, canceled: 6 </param>
Public void isvalidstatetransition (string state, int status)
{
Isvalidstatetransitionrequest request = new isvalidstatetransitionrequest ();
Request. entity = new entityreference () {logicalname = entityname, id = incidentid };
Request. newstate = State;
Request. newstatus = status;
Isvalidstatetransitionresponse response = (isvalidstatetransitionresponse) service. Execute (request );
Bool isvalid = response. isvalid;
}

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

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

CRM operation case 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.