web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Do action method of USD

(0) ShareShare
ReportReport
Posted on by 2,385

Hi,

I need to know the functionality of the doAction() and notifyContextChange() methods of UII Web Applilication adaptor of unified service desk.

How and when these methods gets invoked? what is the relation between these two methods?

I have created a new web application adaptor and when i used that in USD getting below error .

System.NullReferenceException: Object reference not set to an instance of an object.

   at WebApplicationAdapter1.WebAdapter.NotifyContextChange(Context context)

   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)

   at Microsoft.Practices.CompositeUI.State.OnStateChanged(StateChangedEventArgs e)

   at Microsoft.Practices.CompositeUI.StateElement.set_Item(String key, Object value)

   at Microsoft.Uii.Csr.HostedApplicationUtility.SetContextState(Context context, ApplicationHostWorkItem appHostWorkItem, Object modifier)

   at Microsoft.Uii.Csr.ApplicationHost.NotifyContextChange()

   at Microsoft.Uii.Csr.ApplicationHost.SessionChange(Boolean active, Guid sessionID)

   at Microsoft.Uii.Csr.Sessions.SetActiveSession(Guid sessionId)

 

The two respective functions are as follows...

public

 

public override bool DoAction(HostedWebApplication.WebAction action, ref string data)

{

Trace.WriteLine(string.Format(CultureInfo.CurrentUICulture, "{0}>>>>> RECEIVED (WebAction) Action : {1} ", this.Name, action.Name));

// Check to see if the browser is working on something before allowing the system to do 'normal' behavior.

if (Browser.WebBrowser.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)

 {

// Browser is not in a state to process this request,Queue it for when the browser is ready to handle it.

Trace.WriteLine(string.Format(CultureInfo.CurrentUICulture, "{0}>>>>> Browser Busy,({2}) Queuing Action : {1} ", this.Name, action.Name, Browser.WebBrowser.ReadyState.ToString()));

      qReqActionList.Enqueue(new BrowserActionData(action, data));

return false;

    }

Trace.WriteLine(string.Format(CultureInfo.CurrentUICulture, "{0}>>>>>>>>>>> Action:Name={1} Action:Url={2} Action:Query={3} Action:Init={4}", this.Name, action.Name, action.Url, action.QueryString, action.Initialization));

 

// Get browser DOM and element collection./////

// Create an XML Document to load the passed in data to.

HTMLDocument htmlDoc = Browser.Document as HTMLDocument;

IHTMLElementCollection htmlElementCollection = htmlDoc.all;

// Check action name for something we know how to process.

switch (action.Name)

            {

case "UpdateFirstName":

IHTMLElement htmlFirstName = htmlElementCollection.item("PageLayout_txtLogin", 0) as IHTMLElement;

                    htmlFirstName.setAttribute("value", data, 0);

break;

              

case "UpdateLastName":

    IHTMLElement htmlLastName = htmlElementCollection.item("PageLayout_txtPassword", 0) as IHTMLElement;

           htmlLastName.setAttribute("value", data, 0);

break;                  

    }

return base.DoAction(action, ref data)

 }

 

override bool NotifyContextChange(Context context)

{

HTMLDocument htmlDoc = Browser.Document as HTMLDocument;

if (htmlDoc != null)

            {

IHTMLElementCollection htmlElementCollection = htmlDoc.all;

IHTMLElement htmlFirstName = htmlElementCollection.item("PageLayout_txtLogin", 0) as IHTMLElement;

                htmlFirstName.setAttribute("value", "York", 0);

IHTMLElement htmlLastName = htmlElementCollection.item("PageLayout_txtPassword", 0) as IHTMLElement;

                htmlLastName.setAttribute("value", "york2014", 0);

IHTMLElement clickLogin = htmlElementCollection.item("PageLayout_btnLogin", 0) as IHTMLElement;

                clickLogin.click();

}

return base.NotifyContextChange(context);

        }

Any Help on this would be very helpful for me. I have stucked with this long back. Please Help

 

Thanks,

Dilip

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ansrikanth Profile Picture
    3,115 on at

    Hi

    DoAction is a overriden method which will help you to catch hold any actions and perfrom your own actions against to those actions that are firing on this particular host control (in your case it is web adapter). For ex: if a user action came as "Perfrom Login", we will catch that action and internall we will execute our own logic to perform the login mechanism.

    NotifyContextChange: whenever there was a chane in the Session context, this will fire and basically we will use this to catch hold of current context so that you can play with any of those context sensitive variables like Customer Name/account names/numbers etc ..

    What ever the code you are executing, Context changes is not the right place to execute. You can see that this method would execute multiple times during a session progress and that is becuase whenever you add any content to session this would fire. 

    In generally, whatever the code you are doing should ideally be done under an event "DocumentCompleted" event. On load of the adapter, Subscribe to Browser's Document completed event and try to execute your code from there.. That should start working for you .

    The error in your case might be coming becuase the Context change method is executing before your Browser instantiated it self.

    Hope that helps you in undestanding the 2 methods :)

    Happy coding !!

    -Srikanth

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans