Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / May 2005

Tip: Looking for answers? Try searching our database.

Unable to reference a data source element in script?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JC - 11 May 2005 02:55 GMT
Hi,

I am trying the following in VBScript:

   MsgBox XDocument.DOM.selectSingleNode("//my:field1").text

But I get an "Object Required: " error on that line. AFAIK I have the
namespace declared properly... and I do have a "field1" field in my data
source.

Something else I tried, was to right-click the textbox, go to Properties >
Data Validation > Events: OnBeforeChange > Edit, at which point InfoPath
switched to the script editor and inserted the following comment... Note the
3rd line:

'=======
' The following function handler is created by Microsoft Office InfoPath.
' Do not modify the name of the function, or the name and number of
arguments.
' This function is associated with the following field or group (XPath):
/my:myFields/my:field1
' Note: Information in this comment is not updated after the function
handler is created.
'=======

So I edited the line of code to read instead:

   MsgBox XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text

However I receive the exact same error. What am I doing wrong?

Thanks in advance,
JC
Scott Roberts [MSFT] - 12 May 2005 21:49 GMT
I just tried this with a textbox bound to my:field1 and it works.  Can you
explain in more detail how you built your form?

- Scott

> Hi,
>
[quoted text clipped - 29 lines]
> Thanks in advance,
> JC
JC - 13 May 2005 00:25 GMT
Scott,

Thank you for your reply. I am going crazy here :)

When I first started designing the form, I built it by modifying the Issue
Tracking (Simple) sample. Could this be the cause for the problem?

I created a blank form, and the code below works.... So why would it not
work in my actual form?

Thanks again,
JC

>I just tried this with a textbox bound to my:field1 and it works.  Can you
>explain in more detail how you built your form?
[quoted text clipped - 34 lines]
>> Thanks in advance,
>> JC
Scott Roberts [MSFT] - 13 May 2005 00:52 GMT
The Issue Tracking form is pretty complex.  It's possible that something
else in the form is causing this to fail.  If I get a few minutes, I'll try
this in the Issue Tracking form.

- Scott

> Scott,
>
[quoted text clipped - 48 lines]
>>> Thanks in advance,
>>> JC
Scott L. Heim [MSFT] - 13 May 2005 21:36 GMT
Hi JC,

Well modifying one of the built-in samples could be the problem but without
knowing all the modifications you made, it's difficult to tell. However,
let me document the steps I just followed with the same template:

1) Chose to design the Issue Tracking (Simple) Sample
2) Displayed the Datasource Task Pane
3) Right-clicked on the root "issue" element and chose Add
4) Entered a name of: Field1 and clicked OK
5) Dragged Field1 onto the Issue Tracking View
6) Added a button to the Issue Tracking View
7) Edited the code for the button and entered the following (jscript):

         var myFld = XDocument.DOM.selectSingleNode("//my:Field1");
         XDocument.UI.Alert(myFld.text);

8) Previewed the solution, entered Scott in Field1 and clicked the button -
result: a message box was displayed with Scott.

Now I realize these are very basic changes but try these with a new copy of
the sample and let me know the results.

Best Regards,

Scott L. Heim
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Scott L. Heim [MSFT] - 12 May 2005 21:59 GMT
Hi JC,

I placed a text box (named field1) and a button on my form.On the click
event of the button, I have the following:

MsgBox XDocument.DOM.selectSingleNode("//my:myFields/my:field1").text

I then Preview the form, enter Scott in the text box and when I click the
button the message box displays the correct text.  However, if I remove one
of the intial slashes ("/") so that I have: "/my:myFields/my:field1" I get
an empty message box.

Hopefully this will help!

Scott Heim
Microsoft
Scott Roberts [MSFT] - 12 May 2005 22:35 GMT
That's odd b/c when I try it with just one slash it works.  Here is what I
did.  Let me know if this matches what you did.

1. Create a new blank form (Set language to VBScript.)
2. Insert a text box
3. Open the properties dialog of the textbox
4. Click on the data validation button and choose to edit the OnBeforeChange
event
5. Enter MsgBox
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text in the event
handler
6. Preview the form
7. Enter text in the text box and tab away

At this point I see the alert.

- Scott

> Hi JC,
>
[quoted text clipped - 13 lines]
> Scott Heim
> Microsoft
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.