Passing Data into a Form - InfoPath Dev
in

InfoPath Dev

Passing Data into a Form

Last post 06-25-2007 11:39 AM by davidair. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 06-22-2007 06:05 AM

    Passing Data into a Form

    From this Blog:

    http://blogs.msdn.com/infopath/archive/2007/02/26/passing-data-into-a-form-input-parameters.aspx 

    I should be able to run a command line like this:

    infopath.exe “C:\foo\bar.xml” /InputParameters "baz=1&biz=2"

     to pass in parameters to my form.

     

    When I do I get the following error:

    Microsoft Office InfoPath does not recognize some or all of the command line options. Exit and restart MS InfoParth with the correct command line options.

     

    I'm using Infopath 2003 SP2

     

  • 06-22-2007 06:13 AM In reply to

    Re: Passing Data into a Form

    The last line of your post is unfortunately your problem. Command line arguments are only supported in InfoPath 2003.

    See this forum post for some IP2003 workarounds:

    http://www.infopathdev.com/forums/post/20383.aspx

     

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-22-2007 06:17 AM In reply to

    Re: Passing Data into a Form

    That's what I was thinking but later in the blog article it talks about using the parameters in the IP2003 so I was holding out hope.

     

    I'll look into the two links,

    Thanks 

  • 06-25-2007 07:33 AM In reply to

    Re: Passing Data into a Form

    OK,

    I got it to work on my dev box using the following code but when I run it from our production server nothing happens.  I don't really work with jscript so I'm not even sure where to begin debugging.

     

    Here is the relevant code

     

      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ProcId As Integer
        Dim Proc As System.Diagnostics.Process
        ProcId = Shell("cscript \\franklin\c$\Inetpub\wwwroot\shared\Infopath\jscript.js 8275")
        Proc = System.Diagnostics.Process.GetProcessById(ProcId)
        Proc.WaitForExit(3000)
      End Sub

     

    And this is the js file called from above

    if(WScript.Arguments.count()==1)
    {
    var param1 = WScript.Arguments.Item(0);
    }

    //Start the application
    var oApp = new ActiveXObject("InfoPath.Application");
    WScript.Echo("InfoPath Version: " + oApp.Version);

    //Open an InfoPath document from the published template
    var oXDocumentCollection = oApp.XDocuments;
    var oXDocument = oXDocumentCollection.NewFromSolution("http://franklin/shared/infopath/Metro Sales MA.xsn");

    // Get pointers to the target fields
    var oID = oXDocument.DOM.selectSingleNode("//my:PlanId");

    //Determine whether the xsi:nil attribute is set for this
    //element. If so, remove the xsi:nil attributes so that
    //the value can be set.
        if (oID.getAttribute("xsi:nil"))
              oID.removeAttribute("xsi:nil");

    //Update the fields
    oID.text = param1;

    //Submit the Form
    //oXDocument.Submit();

    oXDocument.QueryAdapter.Command = 'SELECT * FROM vwMaPlanForReport WHERE PlanId = ' + param1;

    //execute "dbo"."byroyalty" ' + percentageValue; 
    //Query the Data Source.
    oXDocument.Query();

    oXDocument.DataObjects["Detail"].QueryAdapter.Command = 'execute "dbo"."ps_Reports_MA_Detail_Summary" ' + param1;
    //'SELECT * FROM vwMaPlanEquipmentDetail WHERE PlanId = '
    oXDocument.DataObjects["Detail"].QueryAdapter.Query();

    //Close up shop
    oXDocumentCollection = null;
    //oApp.Quit();
    oApp = null;

  • 06-25-2007 09:08 AM In reply to

    Re: Passing Data into a Form

    Didn't you comment out the line that starts the script in your code? :)
    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-25-2007 09:13 AM In reply to

    Re: Passing Data into a Form

    Oops, that was a error when I copy/pasted, the code I'm testing isn't commented out.

     

    I fixed the code above.

     

  • 06-25-2007 09:22 AM In reply to

    Re: Passing Data into a Form

    Well, it's pretty hard to debug pasted code especially when it is known to work on one environment but not the other, but maybe a couple of pointers:

    - Make sure the InfoPath process get started when you execute the script

    - Try and see if you can replace cscript with wscript. Then add WScript.Echo() lines throughout your javascript code. When executed with wscript, those should appear as mesageboxes. Now you can put those traces at different points of your code to see what is failing

    Sorry that I don't have more suggestions for now...

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-25-2007 09:34 AM In reply to

    Re: Passing Data into a Form

    That helps.

    It's not even running the script file on the production box.

    I change the start of the jscript.js to this:

    WScript.Echo("Start");
    if(WScript.Arguments.count()==1)
    {
    var param1 = WScript.Arguments.Item(0);
    }
    ...

    and I never get the start message box (I do on my local machine).

     
    If I put this string (\\franklin\c$\Inetpub\wwwroot\Shared\Infopath) into my Windows Explorer address bar on the web server it takes me to right folder.
     

  • 06-25-2007 09:45 AM In reply to

    Re: Passing Data into a Form

    Strange... maybe some .NET permissions problems that prevent you from executing scripts on the production machine? It's a wild guess, really. Normally you should get an exception if it doesn't like you.

    Since you are doing a shell exec, try to do a start | run on your production machine and paste the command there - see what happens.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-25-2007 09:56 AM In reply to

    Re: Passing Data into a Form

    It runs but fails on this line:
    var oApp = new ActiveXObject("InfoPath.Application");

    With this error:
    Automation server can't create object

     

  • 06-25-2007 10:03 AM In reply to

    Re: Passing Data into a Form

    Here is a random thought: are you sure that your production machine has InfoPath 2003 SP1 or later?

    I believe InfoPath 2003 RTM simply does not expose InfoPath.Application

    If you're running the RTM version of InfoPath then this is your problem

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-25-2007 10:53 AM In reply to

    Re: Passing Data into a Form

    Not so random, updated to SP1 - the script now runs from the run command.



    Now I just need to get the script to run from my asp page. 

     

    Thanks for all your patience. 

  • 06-25-2007 11:39 AM In reply to

    Re: Passing Data into a Form

    Now that you know your script works, the next thing to do is to look at how you're invoking it. You're doing it like this:

    ProcId = Shell("cscript \\franklin\c$\Inetpub\wwwroot\shared\Infopath\jscript.js 8275")

    You can of course try to do it differently, maybe by doing Process.Start(), passing it the full path to cscript.exe and the rest of the command line as arguments.

    However, I would still suspect you might be running into permission issues since you are doing this from an ASP.NET code which runs under lower priviledges. You might want to check the logs to see if any exceptions happened (not sure where to start looking, though, off the top of my head).

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.