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 callmy 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:
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 ();
From: http://geekswithblogs.net/bpaddock/archive/2004/05/14/4907.aspx