JScript Question

M

Mullie21

I'm having issues assigning a value from JScript to a field. This is the
frist time I've coded in JScript. I read earlier that I had to declare my
namespaces. First question, how do I determine my namespaces? I believe I
only have 'My' because I haven't created any others. I used this to set the
namespace

XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T18:03:47"');

The field I'm trying to put data into is not linked to a database, its just
a field in the form. I'm using the following statement:

function XDocument::OnSaveRequest(eventObj)
{ // Write the code to be run before saving here.

eventObj.IsCancelled = eventObj.PerformSaveOperation();

XDocument.DOM.selectSingleNode("//myFields/my:Saved").text = true;

eventObj.ReturnStatus = true;}

As you can tell, I'm trying to populate a value, when the user saves the
form. I've tried this a million different ways, and everytime I get the same
error, "'XDocument.DOM.selectSingleNode(...)' is null or not an object".

What am I doing wrong? Any help is appreciated.

Thanks,

Chris
 
F

Franck Dauché

Hi Chris,

You don't need to declare anything.
Instead try:
XDocument.DOM.selectSingleNode("/my:myFields/my:Saved").text = true;
Note the initial "/my:"

Hope that it helps.

Regards,

Franck Dauché
 
M

Mullie21

Frank,

Thanks for your help, but that still did not work. I'm still getting that
same error message. Any other ideas?

Thanks again,

Chris
 
M

Mullie21

Also, if I don't declare the namespace, then I get an undeclared namespace
error: "Reference to undeclared namespace prefix: 'my'".

Thanks,

Chris
 
F

Franck Dauché

Hi Chris,

Just to make sure that we are on the same page, create a new blank form.
Drop one textbox on the form. Your schema should be: myFields/field1.
Drop one button, and go to the MSE (right-click on the button / Button
Properties / Edit Form Code) and put the following line of code in the
OnClick event:
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = "test";

run and click the button. Does it work?

Note: you don't have to write any setProperty (it is done by IP
automatically).

Regards,

Franck Dauché
 
M

Mullie21

Frank,

I actually just got it. Instead of using a stored value to determine
whether or not a user had saved the form, I'm going to use the IsNew
function. I've got it working perfectly.

Thanks for your help. This really is a great discussion board.

Chris
 

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