window.dialogArguments from UI.ShowModalDialog is null - InfoPath Dev
in

InfoPath Dev

window.dialogArguments from UI.ShowModalDialog is null

Last post 12-10-2009 09:26 AM by michael412. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-10-2009 05:33 AM

    window.dialogArguments from UI.ShowModalDialog is null

    I have been asked to fix a piece of legacy code that doesn't work. I don't know whether this ever worked, but it looks OK to me as per the documentation and examples.

    Our InfoPath form uses the 2003 object model. Its FormCode.cs calls other assemblies one of which contains the line:

    moderatorId = (string)thisXDocument.UI.ShowModalDialog("UserNamePasswordDialog.htm", thisXDocument, 200, 400, Type.Missing, Type.Missing);

    UserNamePasswordDialog.htm is one of the form's Resources files that gets correctly packaged into the final XSD file. Within this HTML file is script which I have enhanced with some diagnostic tests as follows:

    <script language="jscript" type="text/jscript">
    var gobjXDocument = null;
    var moderatorId = null;
    function Initialize()
    {
        // Save a reference to the XDocument object.
        if (typeof window.dialogArguments == "object")
        {
            gobjXDocument = window.dialogArguments;
        }
        else
        {
            if (null == window.dialogArguments)
            {
                window.alert(
    "window.dialogArguments is null!");
            }
            else
            {
                gobjXDocument = window.dialogArguments;
            }
        }
        if (null == gobjXDocument)
        {
            window.alert(
    "gobjXDocument is null!");
        }
        else
        {
            if (null == gobjXDocument.Extension)
            {
                window.alert(
    "gobjXDocument.Extension is null!");
            }
        }
    }
    function Close()
    {
        //if username or password is blank give val msg in error
        if(UserNameid.value == "")
        {
            errorid.innerText =
    "Please enter a username.";
            errorid.style.display =
    ''; 
        }
        else
        {
            //if username and password are not blank and are valid for this action return and close
            moderatorId = gobjXDocument.Extension.Logon(UserNameid.value, Passwordid.value)
            if(moderatorId)
            {
                //if email is not blank return email and close
                window.returnValue = moderatorId;
                // Close the dialog
                window.close();
            }
            else
            {
                errorid.innerText =
    "The username and password are not valid !";
                errorid.style.display =
    ''; 
            } 
        }
    }
    </script>

    Any time this is run the Initialize method throws up the alerts "window.dialogArguments is null!" and "gobjXDocument is null!". The latter is obviously expected given the occurrence of the former.

    The pertinent questions are of course why is this happening and how do I fix it?

    From browsing various forums I have learned that the most common reason for window.dialogArguments to come through as null is when one is making the ShowModalDialog call cross domain. In this scenario this clearly cannot ever be the case since the form's embedded code is calling one of its own embedded resource files. However, that cross domain business is clearly a security feature so I'm wondering whether there is some other security feature that's causing the issue in my case. My form is configured such that it requires Full Trust. To my understanding this does not actually kick in when running via the debugger (which I am doing), and besides that I have also built the form and signed it and I still get the same result when I run that version.

    So, any ideas anyone?

    Regards,

    Michael

     

  • 12-10-2009 07:41 AM In reply to

    Re: window.dialogArguments from UI.ShowModalDialog is null

     I hadn't heard of this feature before, but it intrigued me, so I decided to experiment with it and came up with the same results as you.  I even tried invoking the dialog from JScript (which most of the examples seem to do), or casting thisXDocument to an object (which one example did and sort of made sense), and no luck.

    What exactly is this dialog supposed to be accomplishing?  Yours seems to be a pretty rare question, so might I propose using the InfoPath form to get the data you want, or if you must use a dialog, to use a WinForm dialog instead?  Either of those approaches carries the benefit of not having to make your form full trust.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-10-2009 08:19 AM In reply to

    Re: window.dialogArguments from UI.ShowModalDialog is null

    Reasonable questions and suggestion Jimmy - thanks. The requirement isn't all that unusual (in fact I've seen several posts from people addressing the same need) - it's obtaining authentication data from the user if an integrated authentication doesn't work. The full trust is actually needed for other reasons (the main one being that the form makes a call to a web service). Your suggestion of using a Windows form is a good one and one that I've seen mentioned in one other place. I haven't tried this before from InfoPath but presumably it's just a matter of creating an assembly with a public method that launches the WinForm, captures the data and returns it to the caller. I'll give that a go - has to be easier than all the nonsense I've tried so far to get this HTML dialog to work.

  • 12-10-2009 08:30 AM In reply to

    Re: window.dialogArguments from UI.ShowModalDialog is null

     Creating and using a WinForm in an InfoPath project is a piece of cake.  You don't need a separate assembly.  Just right-click the project name in the Project Explorer of MSTA, select Add->New Item..., and then Windows Form.  Drag in controls, expose their values with some properties, and add OK and Cancel buttons that set the DialogResult property and call this.Close().

    I'd also suggest using a Data Connection to call your web service if you can.  This also can save you from making the form full trust and InfoPath seems pretty good at handling authentication when you use its built-in web service features.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-10-2009 09:26 AM In reply to

    Re: window.dialogArguments from UI.ShowModalDialog is null

    Magic. Yes, the WinForm was a piece of cake. I did place it in a separate assembly but that was best with the specific assembly level architecture of this particular application. Thanks for the hint re the web service call - I'll have to look into that.

    Best regards,

    Michael

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.