web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Assign a Case to a User, using C#

(0) ShareShare
ReportReport
Posted on by

Hi, guys!

I created a web service, that connects the chat support site of my company to our CRM. It basically creates Cases, and fills in the data that the customers are sending to us via our support site. My only problem is that in order to create a case, I have to log in a user (myself), who will be the creator of the cases.

My question is: How can I assign a case using C# to another user, assuming that I know the Guid of the assignee?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Deepesh161 Profile Picture
    6,317 on at

    Here you go: msdn.microsoft.com/.../gg309540(v=crm.6).aspx

  • Community Member Profile Picture
    on at

    I tried this already:

    AssignRequest assignRequest = new AssignRequest();
    assignRequest.Assignee = new EntityReference("systemuser", consultantID);
    assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid);

    service.Execute(assignRequest);

    The cases however were not assigned to the other user.

  • Deepesh161 Profile Picture
    6,317 on at

    Can you paste the full code here.

  • Community Member Profile Picture
    on at
    [WebMethod]
    
           public void UpdateAssignedPerson(ServiceRequest serviceRequest)
    
           {
    
               var idOfUpdatedItem = serviceRequest.SRID;
    
               var connection = ConnectToDatabase();
    
               var service = new OrganizationService(connection);
    
               var context = new CrmOrganizationServiceContext(connection);
    
               Guid consultantID = findConsultantID(serviceRequest.AssignedPerson, service);
    
               ColumnSet set = new ColumnSet();
    
               set.AllColumns = true;
    
               //Gather the components for the "Retrieve" function
    
               Guid incidentGuid = GetGUIDByName(idOfUpdatedItem, service);
    
               //Retrieves the record that will be updated
    
               var incident = service.Retrieve("incident", incidentGuid, set);
    
               EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson);
    
               try
    
               {
    
                   //Assign a case!
    
                   AssignRequest assignRequest = new AssignRequest();
    
                   assignRequest.Assignee = new EntityReference("systemuser", consultantID);
    
                   assignRequest.Target = new EntityReference(incident.LogicalName, incidentGuid);
    
                   //sets the new User.
    
                   //incident["ownerid"] = new EntityReference("systemuser", consultantID);
    
                   service.Execute(assignRequest);
    
                   service.Update(incident);
    
               }
    
               catch (Exception)
    
               {
    
                   EventLog.saveMessage("Updating the consultant person of case: " + serviceRequest.SRID + "to " + serviceRequest.AssignedPerson + " failed!");
    
                   return;
    
               }
    

    Here is the update method, in which I'm trying to assign the case.

  • Anshuman Profile Picture
    115 on at

    do assign after update, that might help....

    Also, is there an error coming in assign request SDK call?

    If yes, can you paste that? that would be helpful

  • Community Member Profile Picture
    on at

    I tried to assign after I updated but the result is the same.

    I don't get any error or notification, just the case is assigned to the default owner.

  • Suggested answer
    Deepesh161 Profile Picture
    6,317 on at

    Is there some other code which can default your case to some other user. Can you enable audit and see what is happening on the owner field once your code executes?

  • Suggested answer
    Mithilesh Kumar Profile Picture
    10,047 on at

    Hi Georgi,

    The code seems okay to me, however does the users have appropriate access to perform the action to the record.

    Caller should have Assign privilege and assignee should have Read privilege. These are minimum privileges which needs to be set on the entity in question.

    Kindly verify that.

    Hope that helps

    Thanks

    Please mark my post as verified if you found it helpful

  • Deepesh161 Profile Picture
    6,317 on at

    Mithilesh,

    If there were privilege issues, he would have got exception.

  • Mithilesh Kumar Profile Picture
    10,047 on at

    Deepesh,

    You are right, but the code seems okay to me.

    Exception has been caught and but never thrown, rather EventLog class has been used to log the error message.

    Lets see what Georgi has to say on the log.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans