Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to assign a user to a particular activity step

Posted on by Microsoft Employee

how to assign a user to a particular activity step

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to assign a user to a particular activity step

    Hi,

    Do you mean how to assign an activity in Dynamics CRM to a user?

    If so, you could open an activity record navigating by Sales-Activities.

    Click the “Assign” button in the command bar, and choose the user you want to assign this activity.

     6165.1.PNG

    I hope this will work for you. If it works, please Mark this answer as Verified. Thanks.

    Best Regards,

    Judy

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: how to assign a user to a particular activity step

    Hi,

     not sure what an "activity step" means in your question, but you might try using tasks (whenever you need to notify a user that he/she should be working on something, create a task. Might also set up a workflow to do it automatically). Tasks cannot be regarding activities, so you may need to add a lookup to the task entity (or different lookups for different activities)

  • RE: how to assign a user to a particular activity step

    Suppose If your Activity is Task. We can Assign the task to specific users based on specific conditions by using workflow. Below I mentioned the screen shots.

    TaskAssignWorkflow2.png      TaskAssignWorkflow2.png    

    Second way is you can Assign the activities to specific users by using plugin concept.. here I mentioned basic code
     public class Distribution : IPlugin
        {
            private Guid _TaskID;
            int count;
           
            public void Execute(IServiceProvider serviceProvider)
            {
                ITracingService tracingService =
                       (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context =
                     (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                if (context.InputParameters.Contains("Target"))
                {
                    if (context.InputParameters["Target"] is Entity)
                    {
                        Entity entity = (Entity)context.InputParameters["Target"];
                        if (entity.LogicalName == "account")
                        {
                            try
                            {
    //write something
                        }
    Catch(exception e)
    {
    }
                        else
                        {
                           
                            IOrganizationServiceFactory servicefactory =
                                   (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                            IOrganizationService client = servicefactory.CreateOrganizationService(context.UserId);
                            _TaskID = entity.Id;
                            if (((OptionSetValue)entity.Attributes["subject"]).Value == “abc”)
                            {
                                
                                AssignedTo("Undergraduate Nursing Program Team", entity, serviceProvider);
                            }
                            else if (((OptionSetValue)entity.Attributes["subject "]).Value == “dsf”)
                            {
                                                            AssignedTo("Masters Nursing Program Team", entity,serviceProvider);
                            }
    public void AssignedTo(String Teamname, Entity entity, IServiceProvider serviceProvider)
            {
                ITracingService tracingService =
                      (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context =
                     (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory servicefactory =
                                   (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService client = servicefactory.CreateOrganizationService(context.UserId);
                tracingService.Trace(Teamname + "entityname" + entity.LogicalName);
                QueryExpression _queryforteams = new QueryExpression("team");
                _queryforteams.ColumnSet = new ColumnSet(new string[] { "name", "businessunitid", "administratorid" });
                EntityCollection _teams = client.RetrieveMultiple(_queryforteams);
                foreach (var c_team in _teams.Entities)
                {
                    tracingService.Trace(c_team.Attributes["name"].ToString());
                    if (c_team.Attributes["name"].ToString() == Teamname)
                    {
                        QueryExpression _Query = new QueryExpression();
                        _Query.EntityName = "systemuser";
                        _Query.ColumnSet = new ColumnSet(true);
                        _Query.ColumnSet.AddColumn("systemuserid");
                        _Query.LinkEntities.Add(new LinkEntity
                        {
                            LinkFromEntityName = "systemuser",
                            LinkToEntityName = "teammembership",
                            LinkFromAttributeName = "systemuserid",
                            LinkToAttributeName = "systemuserid",
                            LinkCriteria =
                                    new FilterExpression
                                    {
                                        Conditions ={
                                new ConditionExpression("teamid",ConditionOperator.Equal,c_team.Id)
                                                    }
                                    }
                        });
                        EntityCollection team_users = client.RetrieveMultiple(_Query);
                        tracingService.Trace(team_users.Entities.Count.ToString());
                        foreach (var tu in team_users.Entities)
                        {
                            QueryExpression qe = new QueryExpression("Task")
                            {
                                ColumnSet = new ColumnSet(new string[] { "Taskid", "ownerid", "subject" }),
                                Criteria =
    {
    Filters =
    {
    new FilterExpression
    {
    FilterOperator = LogicalOperator.And,
    Conditions =
    {
            new ConditionExpression("ownerid", ConditionOperator.Equal, tu.Id),
        },
    },
    }
    }
                            };
                            tracingService.Trace("Hi");
                            Guid contactId = ((EntityReference)c_team.Attributes["administratorid"]).Id;
                            AssignRequest assign = new AssignRequest
                            {
                                Assignee = new EntityReference("systemuser", contactId),
                                Target = new EntityReference("Task",
                                                   _TaskID)
                            };
                            client.Execute(assign);
                        }
                    }
                }
            }
    }
    }
    }
    }
    }
    }
     
    I hope this will work for you. if it works Please Mark this answer as Verified.
    Suppose If your Activity is Task. We can Assign the task to specific users based on specific conditions by using workflow. Below I mentioned the screen shots.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans