Setting InfoPath query filed values

S

sachintha

Hello All,

I designed an InfoPath form (following an example) to retrieve and
submit data to a database.

Data Sources are as follow (as showed in Data Source view)

-myFields
-queryFields
-q:Suppliers
:SupplierID
:CompanyName
[and other fields]
+q:products
+dataFields

Suppliers and Products are 2 tables in the database.

I want to set the CompanyName query field to some value at the onLoad
form event. I tried in many ways but always give an error message
("null is null or not an object").

JScript code is as follows

---------------------------------------------------------------------------------------------------------------
var
x=XDocument.DOM.selectSingleNode("myFields/queryFields/q:Suppliers/@CompanyName");
x.text = "xxx";
----------------------------------------------------------------------------------------------------------------

Please give me some guidelines to solve this.

Thank you All,
Regards, Sachintha
 
S

S.Y.M. Wong-A-Ton

You need to add the namespaces for "myFields" and "queryFields" to your XPath
expression, otherwise the node will not be found and will result in the error
you're currently getting.
 
S

sachintha

Thank you very much Wong-A-Ton,

I am totally new to infopath and xml expressions. Please tell me from
where I can find
namespaces for "myFields" and "queryFields" and how to add namespaces
to XPath
expression.

Regards,
Sachintha


S.Y.M. Wong-A-Ton said:
You need to add the namespaces for "myFields" and "queryFields" to your XPath
expression, otherwise the node will not be found and will result in the error
you're currently getting.
---
S.Y.M. Wong-A-Ton


sachintha said:
Hello All,

I designed an InfoPath form (following an example) to retrieve and
submit data to a database.

Data Sources are as follow (as showed in Data Source view)

-myFields
-queryFields
-q:Suppliers
:SupplierID
:CompanyName
[and other fields]
+q:products
+dataFields

Suppliers and Products are 2 tables in the database.

I want to set the CompanyName query field to some value at the onLoad
form event. I tried in many ways but always give an error message
("null is null or not an object").

JScript code is as follows

---------------------------------------------------------------------------------------------------------------
var
x=XDocument.DOM.selectSingleNode("myFields/queryFields/q:Suppliers/@CompanyName");
x.text = "xxx";
----------------------------------------------------------------------------------------------------------------

Please give me some guidelines to solve this.

Thank you All,
Regards, Sachintha
 
S

S.Y.M. Wong-A-Ton

If you add this piece of JScript code behind a button

XDocument.UI.Alert(XDocument.DOM.xml);

and then click on it, you can see what the XML for your form looks like and
also which namespaces and namespace aliases it is using. Since I do not know
what your XML looks like, I can only guess at what the XPath expression
should be. So try:

dfs:myFields/dfs:queryFields/q:Suppliers/@CompanyName

and see if that works.
---
S.Y.M. Wong-A-Ton


sachintha said:
Thank you very much Wong-A-Ton,

I am totally new to infopath and xml expressions. Please tell me from
where I can find
namespaces for "myFields" and "queryFields" and how to add namespaces
to XPath
expression.

Regards,
Sachintha


S.Y.M. Wong-A-Ton said:
You need to add the namespaces for "myFields" and "queryFields" to your XPath
expression, otherwise the node will not be found and will result in the error
you're currently getting.
---
S.Y.M. Wong-A-Ton


sachintha said:
Hello All,

I designed an InfoPath form (following an example) to retrieve and
submit data to a database.

Data Sources are as follow (as showed in Data Source view)

-myFields
-queryFields
-q:Suppliers
:SupplierID
:CompanyName
[and other fields]
+q:products
+dataFields

Suppliers and Products are 2 tables in the database.

I want to set the CompanyName query field to some value at the onLoad
form event. I tried in many ways but always give an error message
("null is null or not an object").

JScript code is as follows

---------------------------------------------------------------------------------------------------------------
var
x=XDocument.DOM.selectSingleNode("myFields/queryFields/q:Suppliers/@CompanyName");
x.text = "xxx";
----------------------------------------------------------------------------------------------------------------

Please give me some guidelines to solve this.

Thank you All,
Regards, Sachintha
 

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