zoukankan      html  css  js  c++  java
  • InfoPath: Passing Command Line parameters to a new form

    A frequent question from InfoPath users is “How can I pass parameters to a new InfoPath form when it is created?”

    Unfortunately, there’s no built-in functionality for passing command-line parameters to infopath.exe.

    BUT, that doesn’t mean it can’t be done J

    Note that the solution below requires the InfoPath SP-1 Preview.

    Solution:

    Jscript files can instantiate InfoPath with a new form from a template using NewFromSolution().  Jscript can also access the InfoPath DOM and pass parameters to it.  And finally, Jscript files can also accept command-line parameters.

    Usage: 

    In my case, I wanted my C# application to pass parameters to a new Form.  Basically, the user (running my App) searches the SQL database for a customer (in my case, patient) account.  They can then view/edit all of that account’s data right in the app.  The user can then select a date and time for an appointment and click “Create Encounter.”  This button calls my jscript file, passing it the ID number, date, and time that were selected.  The Jscript file creates a new InfoPath form from the template, and fills in the ID number, date, and time.  The Form Template has the “AfterChange” event for the ID number text box set so that it queries the database with that ID number, which returns that customer/patient’s information and populates all relevant fields in the Form.  It then closes InfoPath, and my application simply says “Encounter file created.”

    The form’s submit code puts it in a SharePoint library with a unique filename generated from the ID number and date/time of the appointment.

    Calling the script:

    In VB .NET, this is a simple matter of:

    Dim ProcID As Integer
    
    Dim Proc As Process
    
    ProcID = Shell("cscript script.js " + IDnum + " " + Date+ " " +Time + " " + AMPM)
    
    Proc = Process.GetProcessById(ProcID)
    
    Proc.WaitForExit(3000)
    
    MsgBox("Form created.")
    

    The Script:

    //myscript.js
    
    //parse parameters
    
    if(WScript.Arguments.count()==4)
    
    {
    
    var param1 = WScript.Arguments.Item(0);
    
    var param2 = WScript.Arguments.Item(1);
    
    var param3 = WScript.Arguments.Item(2);
    
    var param4 = WScript.Arguments.Item(3);
    
    }
    
    //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://server/Forms/template.xsn";;);
    
    // Get pointers to the target fields
    
    var oID = oXDocument.DOM.selectSingleNode("//ID");
    
    var oDate = oXDocument.DOM.selectSingleNode("//my:Date")
    
    var oTime = oXDocument.DOM.selectSingleNode("//my:Time")
    
    var oAMPM = oXDocument.DOM.selectSingleNode("//my:AMPM")
    
    //Update the fields
    
    oID.text = param1;
    
    oDate.text = param2;
    
    oTime.text = param3;
    
    oAMPM.text = param4;
    
    //Submit the Form
    
    oXDocument.Submit();
    
    //Close up shop
    
    oXDocumentCollection = null;
    
    oApp.Quit();
    
    oApp = null;
    

    This is a ready-to-go script file and all you need to change is A) The number of parameters B) The location of your template and C) The names of the fields you wish to populate.  You also may not want to submit the file or close InfoPath.  Or you may want to use oXDocument.SaveAs();

    转自:http://geekswithblogs.net/bpaddock/archive/2004/05/14/4907.aspx

  • 相关阅读:
    新基建的福音:智慧楼宇可视化监控系统引领智能化新时代
    基于 HTML5 和 WebGL 的地铁站 3D 可视化系统
    基于 HTML5 WebGL 的医疗物流系统
    基于 HTML5 的 PID-进料系统可视化界面
    基于 HTML5 Canvas 的可交互旋钮组件
    基于 HTML5 WebGL 的民航客机飞行监控系统
    基于 HTML5 Canvas 的元素周期表展示
    基于 HTML5 换热站可视化应用
    基于 HTML5 WebGL 的 3D 智慧隧道漫游巡检
    【python 爬虫】fake-useragent Maximum amount of retries reached解决方案
  • 原文地址:https://www.cnblogs.com/timy/p/1735268.html
Copyright © 2011-2022 走看看