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:


Explore AI, agents & Microsoft technology.
I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.
Subscribe on YouTube →