473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Read-only Error when Updating Field in IP 2003

Hello;

I've created a form in InfoPath 2003. One of the fields is intended
to be programmatically assigned as it is the next sequential key to
the underlying database.


I finally have all of my namespaces in place to navigate the nodes and
when I execute the following code, I get an error that I can't assign
the value because the DOM is read-only.


Expand|Select|Wrap|Line Numbers
  1. function setNodeValue(xpath, value) 
  2.  
  3.  
  4. '       // Let's do that if the value has really changed. 
  5.         if (xPATH.text <> value) then 
  6.            xPATH.text = value 
  7.         end if 
  8. setNodeValue = xpath.text 
  9. end function 
  10.  

is there an attribute I need to set before I can change the value?


Thanks
May 30 '07 #1
4 1856
dorinbogdan
839 Expert 512MB
Is not it case sensitive? xPATH or xpath?
May 30 '07 #2
dorinbogdan
839 Expert 512MB
Please post the code calling setNodeValue() function, including xpath variable.
May 30 '07 #3
Hi,

Below is the full stream of code. Please note that I am calling from the OnBeforeChange event. The event is triggered after the "Run Query" retrieves the record from the database.

The error occurs after the eventObj.Operation is changed to "Insert".

Also, the code is not case-sensitive.

Thanks,
Gregg

Expand|Select|Wrap|Line Numbers
  1. '/*------------------------------------------------------------------------------
  2. '    initializeNodeValue()
  3. '------------------------------------------------------------------------------*/
  4.  
  5. function initializeNodeValue(xpath, strValue)
  6.  
  7. dim xmlNode 
  8. set xmlnode = getNode(xpath)
  9.  
  10. ' Set the node value *ONLY* if the node is empty.
  11. 'if (xmlNode.text = "")then
  12. setNodeValue xmlNode, strValue
  13. 'end if
  14.  
  15. end function
  16.  
  17. '/*------------------------------------------------------------------------------
  18. '    setNodeValue()
  19. '------------------------------------------------------------------------------*/
  20. function setNodeValue(xpath, value)
  21.  
  22. 'dim xmlNode 
  23. 'xmlNode = getNode(xpath)
  24.  
  25. '    'if isnull(xmlNode)then
  26. '        'exit function
  27. '    'end if
  28.  
  29. '    // The xsi:nil needs to be removed before we set the value.
  30. '    if (value <> "" and xPATH.getAttribute("xsi:nil"))then
  31. '        xPATH.removeAttribute("xsi:nil")
  32. '    end if
  33.  
  34. '    // Setting the value would mark the document as dirty.
  35. '    // Let's do that if the value has really changed.
  36.     if (xPATH.text <> value)then
  37.         xPATH.text = value
  38.     end if
  39. setNodeValue = xpath.text
  40. end function
  41.  
  42. '/*------------------------------------------------------------------------------
  43. '    getNode()
  44. '------------------------------------------------------------------------------*/
  45. function getNode(xpath)
  46.  
  47. DIM MYNODE
  48.  
  49. set MYNODE = Xdocument.DOM.selectSingleNode(xpath)
  50.  
  51. '    // Both XML node and absolute XPath are allowed.
  52.     if (typename(xpath) = "String")then
  53.         set MYNODE = Xdocument.DOM.selectSingleNode(xpath)
  54. '    else
  55. '        xpath
  56.     end if
  57.  
  58. SET getNode = MYNODE
  59.  
  60. end function
  61.  
  62. '=======
  63. ' The following function handler is created by Microsoft Office InfoPath.
  64. ' Do not modify the name of the function, or the name and number of arguments.
  65. ' This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:qryGetLastTestCaseID/@LastOfLastUsedCounter
  66. ' Note: Information in this comment is not updated after the function handler is created.
  67. '=======
  68. Sub msoxd__qryGetLastTestCaseID_LastOfLastUsedCounter_attr_1_OnBeforeChange(eventObj)
  69. ' Write your code here
  70. dim fldnam1 
  71. dim fldnam2
  72. dim fldnam3
  73. const strMyFields = "/dfs:myFields/dfs:dataFields/d:qryGetLastTestCaseID/@LastOfLastUsedCounter"
  74. ' Write code here to restore the global state.
  75.  
  76. If eventObj.IsUndoRedo or eventObj.Operation = "Delete" Then
  77.     ' An undo or redo operation has occurred and the DOM is read-only.
  78.     Exit Sub
  79. End If
  80.  
  81. fldnam1 = eventobj.site.nodevalue
  82.  
  83. if isnumeric(fldnam1) then
  84.    fldnam1=Cstr(Cint(fldnam1)+1)
  85.    fldnam3 = String((MaxTestCaseIDLen-Len(fldnam1)),"0") & fldnam1
  86. 'else   
  87. '   error condition?
  88. end if
  89.  
  90. initializeNodeValue strMyFields, fldnam3  
  91.  
  92. End Sub
  93.  
Jun 1 '07 #4
I have some news. I relocated this code to the OnAfterChange event. I am then able to modify the value of the node without getting the Read-Only error. In order to avoid the event from triggering itself, I had to set a ModifyFlag before entering the event handler.

In any case, I still have a problem. Even though I correctly set the value of the eventobj.site.text, it does not display in the form. But, if I add a msgbox displaying the node's value, it correctly displays it so I know the value was set. Why can't I see it in the form?

Thanks,
Gregg
Jun 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
0
by: munif | last post by:
i wnat write a C++ program that would read from a CD and display information about files and folders in the given CD In simple words you would be performing a simple (ls -l) or (DIR /S) on the...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
0
by: Garrett Kajmowicz | last post by:
I have two implementations of stringstream and they both handle interleaved reads and writes differently. I was hoping that you might be able to shed some light as to the "correct" operation, and...
2
by: Andrea Bauer | last post by:
Hallo, wie kann ich so eine Datei unter .Net schreiben C++ oder C#. Bitte mit Funktionsaufrufen. Vielen Dank. Grüße Andrea <Product> <ProgramNumber>2</ProgramNumber>
4
by: Kai Thorsrud | last post by:
Hi, Thanks a lot for the short path solution to the app i'm working on by including a Perl script ( App i'm converting from perl to .Net) for the part i can't do yet. I'm communicating with a...
3
by: Ole | last post by:
I got a problem with serial port read which I use like this: sp.Read (byteBuffer, 0, 100); but the problem is that it returns before it has read the 100 bytes - is there a way to set up the...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
14
by: chance | last post by:
Hello, I have a file on disk called TEMP.ZIP and I would like to somehow get this into a memory stream so I can eventually do this: row = dataStream.ToArray() However, I am not sure of the...
5
by: Thomas Christensen | last post by:
This issue has been raised a couple of times I am sure. But I have yet to find a satisfying answer. I am reading from a subprocess and this subprocess sometimes hang, in which case a call to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.