Convert JSScript Example to VBScript

R

RobSol

I looked up and example on the Microsoft InfoPath website but it referrenced
it using JSScript however my form is using VBScript. Is there an easy way to
convert this example to apply it to my form?

http://support.microsoft.com/kb/826992

Here is the example:

function MyQuery::OnClick(eventObj)
{
// Get the default SQL command for the form.
var strOrigSQLCommand = XDocument.QueryAdapter.Command;

// Get the query node that you want to modify.
var querySuppliers =
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:Suppliers");

// Obtain the text that was entered for the wildcard character search, and
then clear
// the current query parameter so that InfoPath will leave the current
query parameter blank.
var strTitle = querySuppliers.selectSingleNode("@ContactTitle").text;
querySuppliers.selectSingleNode("@ContactTitle").text = "";

// Ask InfoPath to construct an SQL command that is based on all other
field values.
var strMySQLCommand =
XDocument.QueryAdapter.BuildSQLFromXMLNodes(querySuppliers);

// Save each of the other query items, and then clear the other query
items before the next query.
var strSupplierID = querySuppliers.selectSingleNode("@SupplierID").text;
querySuppliers.selectSingleNode("@SupplierID").text = "";
var strContactName = querySuppliers.selectSingleNode("@ContactName").text;
querySuppliers.selectSingleNode("@ContactName").text = "";
var strPhone = querySuppliers.selectSingleNode("@Phone").text;
querySuppliers.selectSingleNode("@Phone").text = "";

// Add ContactTitle to the query so
// that ContactTitle can support wildcard characters.
if (strTitle != "")
{
if (strMySQLCommand != "")
strMySQLCommand = strMySQLCommand + " AND ";

strMySQLCommand = strMySQLCommand +
"([Suppliers].[ContactTitle] LIKE \"" + strTitle + "\")";
}

// Construct the full query string.
var strSQLQuery = strOrigSQLCommand;
if (strMySQLCommand != "")
strSQLQuery = strSQLQuery + " WHERE " + strMySQLCommand;

// This is the query.
//XDocument.UI.Alert(strSQLQuery);

// Run the query.
XDocument.QueryAdapter.Command = strSQLQuery;
XDocument.Query();

// Restore all the user entries to the Query fields so that the user
entries will
// be available if you want to modify and to rerun the query.
querySuppliers.selectSingleNode("@SupplierID").text = strSupplierID;
querySuppliers.selectSingleNode("@ContactName").text = strContactName;
querySuppliers.selectSingleNode("@ContactTitle").text = strTitle;
querySuppliers.selectSingleNode("@Phone").text = strPhone;

// Restore the default table command (for the next time).
XDocument.QueryAdapter.Command = strOrigSQLCommand;

// Switch to data entry view to see results.
XDocument.View.SwitchView("Data Entry");
 
R

Ravi G (GGK Tech)

Hi,
Follow the following steps, they may help you
Open the form in Designing and go to Tools-->Form Options-->Programming
Select 'VB Script' in 'Form template Code Language' drop down
--
Ravi G


RobSol said:
I looked up and example on the Microsoft InfoPath website but it referrenced
it using JSScript however my form is using VBScript. Is there an easy way to
convert this example to apply it to my form?

http://support.microsoft.com/kb/826992

Here is the example:

function MyQuery::OnClick(eventObj)
{
// Get the default SQL command for the form.
var strOrigSQLCommand = XDocument.QueryAdapter.Command;

// Get the query node that you want to modify.
var querySuppliers =
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:Suppliers");

// Obtain the text that was entered for the wildcard character search, and
then clear
// the current query parameter so that InfoPath will leave the current
query parameter blank.
var strTitle = querySuppliers.selectSingleNode("@ContactTitle").text;
querySuppliers.selectSingleNode("@ContactTitle").text = "";

// Ask InfoPath to construct an SQL command that is based on all other
field values.
var strMySQLCommand =
XDocument.QueryAdapter.BuildSQLFromXMLNodes(querySuppliers);

// Save each of the other query items, and then clear the other query
items before the next query.
var strSupplierID = querySuppliers.selectSingleNode("@SupplierID").text;
querySuppliers.selectSingleNode("@SupplierID").text = "";
var strContactName = querySuppliers.selectSingleNode("@ContactName").text;
querySuppliers.selectSingleNode("@ContactName").text = "";
var strPhone = querySuppliers.selectSingleNode("@Phone").text;
querySuppliers.selectSingleNode("@Phone").text = "";

// Add ContactTitle to the query so
// that ContactTitle can support wildcard characters.
if (strTitle != "")
{
if (strMySQLCommand != "")
strMySQLCommand = strMySQLCommand + " AND ";

strMySQLCommand = strMySQLCommand +
"([Suppliers].[ContactTitle] LIKE \"" + strTitle + "\")";
}

// Construct the full query string.
var strSQLQuery = strOrigSQLCommand;
if (strMySQLCommand != "")
strSQLQuery = strSQLQuery + " WHERE " + strMySQLCommand;

// This is the query.
//XDocument.UI.Alert(strSQLQuery);

// Run the query.
XDocument.QueryAdapter.Command = strSQLQuery;
XDocument.Query();

// Restore all the user entries to the Query fields so that the user
entries will
// be available if you want to modify and to rerun the query.
querySuppliers.selectSingleNode("@SupplierID").text = strSupplierID;
querySuppliers.selectSingleNode("@ContactName").text = strContactName;
querySuppliers.selectSingleNode("@ContactTitle").text = strTitle;
querySuppliers.selectSingleNode("@Phone").text = strPhone;

// Restore the default table command (for the next time).
XDocument.QueryAdapter.Command = strOrigSQLCommand;

// Switch to data entry view to see results.
XDocument.View.SwitchView("Data Entry");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top