USD – Accessing Context Parameters in Custom Hosted Control

Leave a comment

In this post we will look at how to access context parameters in a custom hosted control in C#.

Create a new project in Visual Studio:

You will see:

Update the references using NuGet:

Compile, and deploy by copying the assembly to your USD client folder:

Now create a new Hosted Control in D365:

Fill out the fields:

Now start USD. Open the debugger, you will see the parameters under $Context:

Open the new hosted control through the debugger, default action.

In Visual Studio, attach the debugger to Unified Service Desk. With a breakpoint on the DesktopReady event, we can see the Context is being populated with our ForceChange key:

<UiiContext><ForceChange>f1f126e5-fdbb-4821></ForceChange></UiiContext>

To add a new key and value to replacement parameters of our custom hosted control, we can use MergeReplacementParameter:

        protected override void DoAction(Microsoft.Uii.Csr.RequestActionEventArgs args)
        {
            // Insert into the Context
            var data = new List { new LookupRequestItem("New Context Key", "New Context Value") };
            var r = (DynamicsCustomerRecord)localSession.Customer.DesktopCustomer;
            r.MergeReplacementParameter(ApplicationName, data);

            base.DoAction(args);
        }

In running this from DoAction, for example, This produces:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *