Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

Changing Appointment Owner to Queue

(1) ShareShare
ReportReport
Posted on by 460
Hi,
 
We would like to automatically change the Owner of an Appointment to the Queue to which the Owner belongs to.
So for example, if I create an Appointment now, I am the Owner, but I belong to the Technical Support Queue, how can I create a workflow that automatically changes the Owner to the Technical Support Queue. 
I have looked at a workflow using either an assign or Update Record, the Assign option will only allow me to select a User or Team and not the Queue, and the Update Record step wont give me an option to update the Owner.
 
Thanks
Ted
  • Suggested answer
    Ali Hamza Profile Picture
    Ali Hamza 24 on at
    Changing Appointment Owner to Queue
    You can use Power Automate FLOW or a plugin to achieve this functionality. You will need to set Activity party object in the form. 
     
    Here is sample code, please test first at your end. You will need to register plugin using Plugin registration code and register step on create of appointment entity / table. 
     
    using System;
    using System.Linq;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    public class SetAppointmentFromField : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            
            // Check if the target entity is Appointment and if it's being created or updated
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity targetEntity &&
                targetEntity.LogicalName == "appointment")
            {
                // Obtain the organization service
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                
                try
                {
                    // Get the current user ID
                    Guid currentUserId = context.InitiatingUserId;
                    // Query queues where the user is a member
                    QueryExpression query = new QueryExpression("queue")
                    {
                        ColumnSet = new ColumnSet("queueid", "name"),
                        Criteria = new FilterExpression
                        {
                            Conditions =
                            {
                                new ConditionExpression("primaryuserid", ConditionOperator.Equal, currentUserId)
                            }
                        }
                    };
                    EntityCollection queues = service.RetrieveMultiple(query);
                    if (queues.Entities.Any())
                    {
                        // Use the first queue found (or apply your own logic to determine which queue to use)
                        Entity queue = queues.Entities.First();
                        EntityReference queueReference = new EntityReference("queue", queue.Id);
                        // Update the "From" field of the appointment
                        if (targetEntity.Attributes.Contains("from"))
                        {
                            targetEntity["from"] = new EntityCollection(new Entity[]
                            {
                                new Entity("activityparty")
                                {
                                    ["partyid"] = queueReference
                                }
                            });
                        }
                        else
                        {
                            targetEntity.Attributes.Add("from", new EntityCollection(new Entity[]
                            {
                                new Entity("activityparty")
                                {
                                    ["partyid"] = queueReference
                                }
                            }));
                        }
                    }
                    else
                    {
                        throw new InvalidPluginExecutionException("The current user is not associated with any queue.");
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException($"An error occurred in the SetAppointmentFromField plugin: {ex.Message}", ex);
                }
            }
        }
    }
     
  • Joseph Melillo Profile Picture
    Joseph Melillo 116 on at
    Changing Appointment Owner to Queue
    Queues cannot be included in the Owner field polymorphic lookup in Dynamics 365. The Owner field strictly supports only User and Team entities. This behavior is by design in Dynamics 365 Customer Engagement and cannot be changed directly.
  • Ian_P Profile Picture
    Ian_P 58 on at
    Changing Appointment Owner to Queue
    I cannot see an Organizer field so this must be a customization.  It will then depend what relationship or lookup you have assigned to the field.
     
    Normally an Owner type field is a User or Team.
     
    Can you not set the value to Team associated to the Queue instead?
  • TedW Profile Picture
    TedW 460 on at
    Changing Appointment Owner to Queue
    Hi,
     
    Just to further clarify, its not the Owner I need to change, its the Organizer, as the Organizer is the 'From' field in the Appointment.
     
    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans