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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator 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.

  • Suggested answer
    Mahendar Pal Profile Picture
    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
    Hemant Kumar Sahu Profile Picture
    1,829 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

  • Community Member Profile Picture
    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
    1,829 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

  • Suggested answer
    Community Member Profile Picture
    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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans