Working with context

Aug 6, 2011 at 7:34 AM

Hi all

I've read this article about adding values to context. I've done everything that was described, that is created new context variable, added values to it, and called FireChageContext. Everything wents correctly, new values are created in context, however, IMHO, after I call this method, SetContext is called internally by UII, so my created context is being overidden  by new context. If i'm not right please correct me. And so I have this question. How can I get the context of the Active session, and only after that in stead of creating new context variable, get the current session context and add values to it?

And the second question. Could anyone provide a link to article, where event processing pipeline of CCA is described? I think it's quit messy.

Thanks everybody for answers

With respect

Gagik Kyurkchyan

Aug 6, 2011 at 4:00 PM

On Context,
Context is UII is tied to a given Session, Context is also a “pointer” (though you really don’t have pointers in C# in the C++ sense, it is a shared object).   When you Call FireChangeContext, the session context var is replaced by the new context you created, the old one is disposed of.
UII then will call NotifiyContextChange for every hosted control in the current session except for the control that initiated the request; it will also call DesktopContextChange on which ever control is hosting the IContextManager.

DesktopContextChange is there to allow you to do an update to the session and if necessary, by returning “true” from it, force a session refresh. Most of the time, you don’t need to worry about this method, unless you’re creating an “empty session” and going to populate the customer payload and session information based on an additional action. IE, the business requirements do not allow for you to know what the session is about at the time it’s created.

To your question, you will get notified of the Active Context object via the Notify Context override in your adapter or hosted control, You can also use the HAT RegisterforEvent shape to listen for it.
that will hand you a pointer to the current context. To change it, you use this pattern :

Context NewContext = new Context(OldContext.GetContext());
NewContext["myNewKey"] = "some value";
FireChangeContext(new ContextEventArgs(NewContext));

In hosted controls you can directly access the current context using this.Context, in adapters you need to store it in a local var as the anchor object is not exposed.

I provided a number of solution starters and control templates here if you want to use them, they lay out the boiler plate code for working with most of the UII events that you would need in a hosted control or in an adapter. * Note I will be putting up seveal updates to the desktop starter later this week to fix some issues with the auth control.


For the last question,
Which event pipeline are you interested in ? :) There are 5 distinct pipelines built into the system,

They are:
Start up
ContextChange (which I described above mostly)



Aug 8, 2011 at 5:22 AM

Thanks a lot for detailed answer, and for useful link.

I also have some problem passing context variables as query strings to CRM forms.

I want to initialise Phone Call activity form using query string parameters, but it doesn't work for none of the fields. E.g. i've created simple text field: new_test, and in here is the query string I pass:  http://testcrm/Armsoft/activities/phone/edit.aspx?new_test=testvalue, when I press enter, it refreshes the page, and no error is generated, however the new_test field is empty. I've read this article  of how to enable query string parameter passing, but it doesn't help too. I've posted this question in CRM forum but they said it's unsupported for CRM 4.0, and no one answered this question. But I know this work for other web hosted applications. 

Can you help me with this? Thanks!

Gagik Kyurkchyan

Aug 10, 2011 at 2:56 AM

Ok, if this is CRM 4 you’re working with, to my knowledge putting params on the query string to get them to load into the CRM window is dodgy at best..
For CRM 4, Your better off doing a UI automation to load it to the UI, Note however, you can use common CRM 4 URL nomenclature. For example, if you create a Phone Activity from an Account, you will notice that the URL has a CreatedFrom var set to the object ID of the Creating Record, it also has the ETC to defined the type. You will need to use an automation to click the “From” button on the activity though.

If your using CRM 2011, this is similar, but different…

Aug 10, 2011 at 5:10 AM

Thanks for the answer.

Gagik Kyurkchyan