2

So, on a completely unrelated issue, I was checking the PendingServiceRouting field reference in the omni-channel developer guide, when I came across a field called PreferredUserId and I was like shut-the-front-door! This is exactly what omni-channel has been missing - a way to route to a specific user.

Further digging reveals this was slipped into Summer '19 (API v46.0) with little fanfare. In fact, it's mentioned only once in the release notes.

There's practically nothing out there that I can find relating to this new feature. So, I figured the enquiring minds on StackExchange could help me test it / validate my findings, for the benefit of others.

Everybody loves sample code. This shows the properties I'm setting on the PendingServiceRouting record (various helper methods excluded for brevity).

private static void createPSR(Case cse, List<String> skills, Id preferredUserId, Integer weight)
{
    // create a new skills-based PendingServiceRouting
    PendingServiceRouting psr = new PendingServiceRouting(
        CapacityWeight = weight,
        IsReadyForRouting = false,
        RoutingModel  = 'MostAvailable',
        RoutingPriority = getRoutingPriority(cse),
        RoutingType = 'SkillsBased',
        ServiceChannelId = getChannelId('Omni_Cases'),
        WorkItemId = cse.Id,
        PreferredUserId = preferredUserId,
        PushTimeout = 0,
    );
    insert psr;

    // do stuff here to create SkillRequirements based on the skill names passed in
    // ...

    // update PendingServiceRouting as IsReadyForRouting
    psr.IsReadyForRouting = true;
    update psr; 
}

What I've discovered, so far:

If you set PreferredUserId and the preferred user is logged in

  1. If you don't have SkillRequirements, omni-channel assigns the case to the preferred user. This is expected, so great.

  2. However, if you do have SkillRequirements, omni-channel steamrolls over them and assigns the case to the preferred user anyway, regardless of whether they also meet the skill requirements. Awesome, that's not quite right.

If you set PreferredUserId and the preferred user IS NOT logged in

  1. If you don't have SkillRequirements, omni-channel assigns the case to any logged in agent based upon the RoutingModel set in the PendingServiceRouting.

  2. If you do have SkillRequirements, omni-channel assigns the case to any logged in agent based upon the SkillRequirements and RoutingModel set in the PendingServiceRouting.

In summary

The preferred user needs to be logged into omni-channel. If they're logged in, it'll route to them regardless of skills. If they're not logged in, it ignores the property completely and behaves as you would expect had it not been set.

Issues

If it's going to completely ignore the skills when the preferred user is online, it's pretty much treating it like 'give it to this person - no matter what'. So the user experience is selecting an agent and the WorkItem ends up with them.

However, the user experience when selecting an offline agent is that it routes as normal if you use skills (but doesn't end up with the preferred user), or disastrous if you don't use skills (any random agent is getting that one).

Why wouldn't it throw the request to the skills backlog if the agent was offline? The user experience would be the same (when they came online again).

Anyway, my fix for this is to only let users select agents that are online.

@AuraEnabled
public static List<User> APEXgetUsers()
{
    // select only logged in users
    // PendingServiceRouting.PreferredUserId is exactly that. Preferred.
    // if the user isn't logged in, it'll go to whoever meets that skills
    // if it's routed without skills, just a preferred user, and that user
    // isn't logged in, it'll go to anyone
    List<User> users = [SELECT Id, FirstName, LastName 
                        FROM User 
                        WHERE IsActive = true 
                        AND Id IN(
                            SELECT UserId FROM UserServicePresence 
                            WHERE IsCurrentState = true
                        )
                        ORDER BY LastName ASC];
    return users;
}

So (I think) the rules are:

  1. You can only route directly to an agent that is online.
  2. You cannot route directly to an agent and also specify skills.

Happy to hear anyone else's feedback.

  • You cannot route directly to an agent and also specify skills, this is done by the system not you – Remario Dec 10 '19 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.