OldValue not available in OnAfterChange event - InfoPath Dev
in

InfoPath Dev

OldValue not available in OnAfterChange event

Last post 10-22-2007 10:58 AM by Greg Collins. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 10-08-2007 03:33 PM

    OldValue not available in OnAfterChange event

    I'm trying to set up a many-to-many relationship between items and grades without a database. I set up a repeating group with a single field for the grades. The grade is displayed in a drop down list. When a grade is selected, it is associated with the item number. I also want to copy one or more item numbers to the grade. I created a grade-item group under the grade with a grade-item-number field. I wrote some VBScript in the OnAfterChange event to that traverses the nodes and inserts a new node with the item number under the grade. It works fine until I delete a grade from the item using the 'Remove Grade' option on the repeating list control. For some reason the OldValue in the OnAfterChange event is no longer available so I can't find the item number that I need to traverse the tree and find the node to delete. I tried finding the OldValue in the OnBeforeChange and it wasn't available there either. Any idea why the OldValue wouldn't be available? Or how I can work around the problem?

    Thanks in advance for any light you can shed on this.

    Regards.


     

    bill
  • 10-08-2007 04:24 PM In reply to

    Re: OldValue not available in OnAfterChange event

    The OnAfterChange event is typically fired twice, once for Operation=="Delete" and once for Operation=="Insert". You will want to handle each of these operations separately.

  • 10-08-2007 06:15 PM In reply to

    Re: OldValue not available in OnAfterChange event

    Thanks for the response Greg, but I guess it wasn't clear that I've already done that. There's no problem with the insert and delete events when I change a drop down list row. I've handle that and it works fine. However, when I delete a row from the drop down list,  the OldValue is not available. I can post the XML and explain it better when I'm back at work tomorrow...

    bill
  • 10-09-2007 07:07 AM In reply to

    Re: OldValue not available in OnAfterChange event

     Greg,

     I've uploaded my test form. In order to show the error do the following:

    • preview
    • use button at top to switch to grade view
    • enter 'grade 1' and 'grade 2'
    • use button at top to switch back to default view
    • add data for 'item 1' and 'item 2'
    • with item 2 selected, click 'insert grade filters' in the lower section
    • select 'grade 1' off the drop down
    • insert another row and select 'grade 2' off the drop down
    • click the drop down menu and then 'remove grade'
    • a message will display indicating that the OldValue is null

    Regards.
     

     

    bill
  • 10-09-2007 04:35 PM In reply to

    Re: OldValue not available in OnAfterChange event

    Yes, I see what you are saying. I can't give an explanation for why the OldValue is NULL, however, running it in the debugger I see that eventObj.Source and eventObj.Site both point to the node that is about to be deleted. From either of these you can get the old value.

    eventObj.Site.text will give you "grade2" in the steps you provided.

    I hope this helps.

  • 10-10-2007 06:52 AM In reply to

    Re: OldValue not available in OnAfterChange event

     Greg,

    Thanks for verifying the problem. I also noted that eventObj.Source and eventObj.Site have the old value in them. However, both eventObj.Source and eventObj.Site appear to be disassociated from the original XML path. Their parent appears to be the document itself. For that reason, I can't traverse the tree to find out what item they were associated with and therefore, I can't remove the grade-item-number node that was added/updated in the grade-item-grp for that item.

    I think I have a work-around that will allow me to complete the project. I think I can train the users to select the empty item from the list in order to remove both the grade and grade-item-number nodes. I will have access to both the NewValue and the OldValue and I think I can delete the node via code. Of course the OnAfterChange event will fire again after the delete, but I think I can set a flag to bypass the If eventObj.Operation = strDelete code. I'll let you know if that works.

    Regards.
     

    bill
  • 10-10-2007 02:34 PM In reply to

    Re: OldValue not available in OnAfterChange event

    Selecting the empty string at the top of the drop down list works. Although it's not pretty and requires some user training, it gets the job done.

    Cheers! 

     

    bill
  • 10-22-2007 10:58 AM In reply to

    Re: OldValue not available in OnAfterChange event

    I believe the object is disassociated because it has already been deleted from the DOM and you are seeing it just before its bits are destroyed.

    Your solution will work fine so long as people follow the instructions. I'm sorry there wasn't a more viable solution for you.

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.