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:
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