Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

Posted on by Microsoft Employee

Hi,

I am trying to write the plugin code in dynamic CRM 2016 on-premise for when record is created then automatically record should be assigned to specific user and campaign. so can any one help me.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    Hi,

    either the user checks every time his "my record" view

    or you create a workflow which create a task activity saying that he needs t review the corresponding record because it was assigned to him.

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    He will become owner, From Views user can see the records.

    Hemant

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    Ok. How user knows about assigned records?

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    Hi Indrasena,

    Please go through this..

     // Create the Request Object and Set the Request Object's Properties

                       AssignRequest assign = new AssignRequest

                           {

                               Assignee = new EntityReference(SystemUser.EntityLogicalName,

                                   _otherUserId),

                               Target = new EntityReference(Account.EntityLogicalName,

                                   _accountId)

                           };
    https://ssharmacrm.wordpress.com/2016/05/03/how-to-assign-a-record-to-a-new-owner/

    msdn.microsoft.com/.../gg309540.aspx

    Hemant

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    Hello,

    In additional to that here is one sample from CRM SDK

    msdn.microsoft.com/.../gg309540.aspx

    Thanks

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to Assign the record to particular user through programatically in dynamic crm2016 on-premise?

    I am not sure what you mean to assign to campaign, as campaigns use marketing lists.

    Regarding assigning the ownership of a record to a particular entity you can use the following code:

           /// <summary>

           /// Changes the Ownership of a record

           /// </summary>

           /// <param name="entityname">The name of the entity that is being assigned to</param>

           /// <param name="id">The Guid of the entity record that is being assigned to</param>

           /// <param name="ownerid">The user unique id that is becoming the assignee</param>

           public void AssignOwnership(string entityname, Guid id, Guid ownerid)

           {

               AssignRequest request = new AssignRequest();

               request.Target = new EntityReference(entityname, id);

               request.Assignee = new EntityReference("systemuser", ownerid);

               try

               {

                   AssignResponse response = (AssignResponse)service.Execute(request);

               }

               catch (FaultException<OrganizationServiceFault> ex)

               {

                   tracingService.Trace("Error Assigning Record: {0}", ex.Message);

                   throw new InvalidPluginExecutionException(ex.Message);

               }

           }

    To call the function your basically specify the entity name, entity id and user id

    If you use the LocalPluginContext for example, you can set it like this:

               string entityName = localContext.PluginExecutionContext.PrimaryEntityName;

               Guid entityId = localContext.PluginExecutionContext.PrimaryEntityId;

               Guid userId = localContext.PluginExecutionContext.UserId;

               AssignOwnership(entityName, entityId, userId);

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans