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 :
Service | Customer Service, Contact Center, Fie...
Suggested answer

Changing Appointment Owner to Queue

(2) ShareShare
ReportReport
Posted on by 479
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
I have the same question (0)
  • TedW Profile Picture
    479 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
  • Ian_P Profile Picture
    64 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?
  • Joseph Melillo Profile Picture
    125 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.
  • Suggested answer
    Ali Hamza Profile Picture
    170 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);
                }
            }
        }
    }
     

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 62

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 26 Super User 2025 Season 2

#3
CU29080825-0 Profile Picture

CU29080825-0 16

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans