Obtain the current conversation ID using the Omnichannel JavaScript API

Are you doing some custom development to extend Dynamics 365 Omnichannel for Customer Service? Perhaps you’re building something in a side pane of Customer Service workspace, or perhaps its a pop up you’re surfacing a HTML web resource in side of using .navigate() to… READ MORE [https://lowcodelewi
coding on a laptop
Photo by cottonbro studio on Pexels.com
In: Low Code Lewis Content 🚀

Are you doing some custom development to extend Dynamics 365 Omnichannel for Customer Service? Perhaps you’re building something in a side pane of Customer Service workspace, or perhaps its a pop up you’re surfacing a HTML web resource in side of using .navigate() to pass data to?

But what if you wanted to utilise the conversation ID of a current active conversation session in Omnichannel to leverage context from the conversation in your feature? In this short post, I’ll show you how to obtain the conversation ID using the Omnichannel JavaScript API, so you can then pass it to a side pane, pop up or something else like a process you may have developed!

Omnichannel JavaScript API

To obtain the current conversation ID we will use a method within the Omnichannel JavaScript API. We can call getConversationId which will return a promise we then need to handle to get the conversation GUID.

Syntax

The syntax to return the promise that once fulfilled will hold our conversation GUID is…

Microsoft.Omnichannel.getConversationId();

If we run this in the browser console directly things will look a little like this…

So, now we need to handle the promise to get the GUID value back.

async function

So in my case, I’m executing my code from a command button on the ribbon of the conversation form. So I’m going to write an asynchronous function that uses await to then get my conversation GUID back. This will look a little bit like this…

async function myLogic() {
     const getConversationId = async () => await Microsoft.Omnichannel.getConversationId();
     const conversationId = await getConversationId();
}

Then once this code has executed, I can use conversationId further down in my myLogic function which now holds my conversation GUID! Awesome!

How will you use this?

So, that’s all there is to obtaining the current conversation GUID in JavaScript to be utilised in other code and logic. Let me know what you’d use this for in the comments section of this post so we can all share ideas and build together! 🚀

Did you like this content? 💖

Did you like this content? Check out some of the other posts on my blog, and if you like those too, be sure to subscribe to get my posts directly in your inbox for free!

Subscribe
Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.