Repeating Table Event Handler - InfoPath Dev
in

InfoPath Dev

Repeating Table Event Handler

Last post 08-04-2005 06:39 AM by smaur. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-27-2005 01:24 PM

    • smaur
    • Not Ranked
    • Joined on 06-17-2005
    • Posts 19

    Repeating Table Event Handler

    I have a form based on an Access database. The database has a main table (called tblRequests) to which users can submit data. The main table has a one to many with a second table (repeating table called lkpComments). On my form I show one record from the main table, and many records (comments) from the second table). Users can add comments at will, but I want to prevent a user from deleting a comment that belongs to someone else. Therefore, my comments table includes a field titled "CommentBy" which holds the name of the person who originally entered it.
    I want to be able to compare the current UserName with the name in the CommentBy field of the repeating table entry that currently has focus so that I can prevent it's deletion.
    This is what I have so far, but there is something wrong with my reference to the @CommentBy field. (I think it is because I need to somehow refer to the specific "comment" entry that has the focus).
    Any ideas? Thanks!

    function msoxd_d_lkpComments::OnBeforeChange(DataDOMEvent)
    {

    //determine the current user
    var oNetwork = new ActiveXObject("WScript.Network");
    var strUserName = oNetwork.UserName;

    //check to see if the current user is the owner of the comment
    if (strUserName == XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblRequests/lkpComments/@CommentBy").text)
    {
    //allow deletion of the record
    }
    else
    //prevent deletion of the record
    if (DataDOMEvent.Operation == "Delete" && DataDOMEvent.Site == DataDOMEvent.Source && DataDOMEvent.NewValue == null)
    {

    DataDOMEvent.ReturnStatus = false;
    DataDOMEvent.ReturnMessage = "You cannot delete this record";
    }
    }
  • 07-28-2005 12:15 PM In reply to

    Re: Repeating Table Event Handler

    Hi smaur,
    My guess is you are having OnBeforeChange on "lkpComments" node
    Here instead of using full xpath you just need to use "@CommentBy" xpath on DataDOMEvent.Source node
    XDocument.DOM.selectSingleNode(DataDOMEvent.Source, "@CommentBy").text

    Agni
    InfoPath Dev India
  • 07-28-2005 01:31 PM In reply to

    • smaur
    • Not Ranked
    • Joined on 06-17-2005
    • Posts 19

    Re: Repeating Table Event Handler

    Thanks for your reply Agni,
    If I understand correctly, I should replace the full path statement I am currently using:
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblRequests/lkpComments/@CommentBy").text)
    with:
    XDocument.DOM.selectSingleNode(DataDOMEvent.Source, "@CommentBy").text
    ...but when I do this I get an error stating...
    Wrong number of arguments or invalid property assignment
    File:script.js
    Line:208

    where line 208 is the line witht the path.

    I appreciate your help.


  • 07-28-2005 03:27 PM In reply to

    Re: Repeating Table Event Handler

    I am sorry smaur, i made a mistake in my code, here is the actual code that will work for
    DataDOMEvent.Source.selectSingleNode("@CommentBy").text




    Agni
    InfoPath Dev India
  • 07-29-2005 11:18 AM In reply to

    • smaur
    • Not Ranked
    • Joined on 06-17-2005
    • Posts 19

    Re: Repeating Table Event Handler

    Agni,
    Thanks for your help.
    I corrected the code as you suggested,

    The problem now is that my test for
    strUserName == DataDOMEvent.Source.selectSingleNode("@CommentBy").text
    always results in True.
    That is if the current UserName appears even once in the @CommentBy field in the repeating table, then he can delete any repeating table entry. My intent was to allow a user to delete only the comments which he has entered.
    The only time a user is prevented from deleting a comment is when he has not made a single comment.

    Perhaps I don't fully understand the capabilities/limits of the repeating table control. If the user has selected a particular line in the repeating table, is there a way to extract a piece of data in a field on the line that currently has the focus and then do a comparison with that single data point?

  • 08-04-2005 06:39 AM In reply to

    • smaur
    • Not Ranked
    • Joined on 06-17-2005
    • Posts 19

    Re: Repeating Table Event Handler

    Thanks to Agni, this now works,

    function msoxd_d_lkpComments::OnBeforeChange(eventObj)
    {
    var oNetwork = new ActiveXObject("WScript.Network");
    var strUserName = oNetwork.UserName;

    if (eventObj.Operation == "Delete" && eventObj.Site == eventObj.Source && eventObj.NewValue == null && strUserName != eventObj.Source.selectSingleNode("@CommentBy").text)
    {
    eventObj.ReturnStatus = false;
    eventObj.ReturnMessage = "You cannot remove a comment entered by someone else";
    }

    else
    {
    //allow deletion
    }
    }
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.