Deleteing from repeating group on changing event of another field - InfoPath Dev
in

InfoPath Dev

Deleteing from repeating group on changing event of another field

Last post 09-09-2012 05:05 PM by petrel. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 02-04-2008 05:28 AM

    Deleteing from repeating group on changing event of another field

    I am using Infopath 2007 and vb.

    I have a dataset
    Aliases Y/N
    AliasesGroup (repeating)
       Aliases

    I want the user to answer Y/N to the Aliases Y/N prompt and if the answer is Yes then display the Aliases.  This works fine.

    If Aliases are already present and the User changes the Y/N prompt to N  I prompt the user on the changing event to see whether they really want to delete the Aliases. 
    If they say no  then I rollback the change - this works fine
    If they say yes - they really want to delete the Aliases I try to set the value of the first one present to "" and delete the rest.  In both cases I get the error Operation is not valid, because of the current state of the object.  How do I find out what is the state of the object ?  Is there a better way to do this ? - My code is below 

    Public Sub AliasesYN_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)
    ' Ensure that the constraint you are enforcing is compatible
    ' If you are changing the alias to No and Aliases already exist prompt user

    If e.OldValue = True And e.NewValue = False Then
    Dim reply As DialogResult = MessageBox.Show("This will delete the existing Aliases", "Do you want to continue", MessageBoxButtons.OKCancel)

    If reply = DialogResult.Cancel Then
       e.CancelableArgs.Cancel = True
       e.CancelableArgs.Message = "The change has been rolled back"
       e.CancelableArgs.MessageDetails = "Changes have been rolled back, because they will be overwritten by changes in the Directory next time the contacts are checked"

    Else
       
    Dim grp As String = "/my:AliasesGroup"
       
    Dim fld As String = "/my:AliasesGroup/my:Aliases"
       
    Dim nav As XPathNavigator
       
    Dim itgroup As XPathNodeIterator

        nav = e.Site.CreateNavigator.SelectSingleNode(grp, NamespaceManager)
        itgroup = nav.Select(fld, NamespaceManager)

        Dim norecs As Integer = itgroup.Count
        Dim mov As Boolean = itgroup.MoveNext

           While mov = True
                 itgroup.Current.SetValue("")
                 itgroup.MoveNext()
                
    While mov = True
                       
    itgroup.Current.DeleteSelf()
                        itgroup.MoveNext()
                
    End While
          
    End While

    End If

    End If

    End Sub

     

  • 02-04-2008 10:18 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    Off the top of my head, the data is read-only during the changing/validating events.

    What is means is that you should do your changes in changed event instead:

    1. In changing, do your test for cancellation and roll out as appropriate

    2. In changed, do the changes you wanted

    Note that if you cancelled #1, #2 would not happen so you no longer need to have the "else" clause.

    Hope this makes sense!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-05-2008 06:46 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    Thank you for your help.  I didn't realise (or had forgotten) about the data being read only during changing/validating events.  Yes it does make sense.  I have got to the next stage....

    I have set the following when the user tries to remove the last item in a group on the group_changing event
    e.CancelableArgs.Cancel = True
    e.CancelableArgs.Message = "Cannot Remove the last item"
    e.CancelableArgs.MessageDetails = "The last item cannot be removed, Select N in Alias Y/N"

    But the message I get displayed is
    The item cannot be removed
    Invalid update: A custom constraint has been violated.

    If I comment out the code in the event... the item gets removed.  So my code is definitely being called.  But I don't know where my message is going and why the (presumably) standard message is coming from.

    Catharine

  • 02-05-2008 12:58 PM In reply to

    Re: Deleteing from repeating group on changing event of another field

    Hmm, I tried to re-create the problem but I got the right message. If you cannot resolve this issue you can maybe attach the form which has the problem (don't forget to include source code) and I could take a look.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 08-12-2008 03:56 PM In reply to

    • arduk
    • Not Ranked
    • Joined on 11-28-2007
    • Posts 10

    Re: Deleteing from repeating group on changing event of another field

    Just wondering if you got a resolution to this - I am encountering the same problem - the error message is always the default error message, no matter what I put in the as the Message or MessageDetails.

    Ideally, I would like to turn off this message altogether - do you know if there is a way to do this?

    Thanks in advance for any assistance!

  • 09-23-2008 12:19 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    I am also facing the same problem.

    I have written following code in changing event of repeating table.

    //////////////// 

    e.CancelableArgs.Cancel =
    true;

    e.CancelableArgs.Message= "Can not insert data";

    e.CancelableArgs.MessageDetails = "Not allowed to insert new details";

    ////////////////

     But i am getting following infopath default message,

    Invalid update: A custom constraint has been violated.

     

    Please help....

     

  • 09-23-2008 12:39 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    Hi David,

    I am facing problem while giving cutom message to the user while inserting new table by clicking insert item of a repeating table.

    I m doing following in RepeatingTable-changing event

    public void RepeatingTable_Changing(object sender, XmlChangingEventArgs e)

    {

    if (e.Operation == XmlOperation.Insert)

    {

    e.CancelableArgs.Message = "Can not insert new address";

    e.CancelableArgs.MessageDetails = "Not allowed to insert new address data";

    e.CancelableArgs.Cancel = true;

    }

    }

    But I always get default Infopath message

    Message - The item can not inserted. 

    Message Details -" Invalid update: A custom constraint has been violated."

     

    Is there any way to avoid this ?

    Thanks,

    Makarand 

  • 07-17-2009 06:19 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

     

  • 06-14-2012 11:54 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    Hi All,

     Invalid update: A custom constraint has been violated. It happens when editing a textbox inside a repeating section or deleting a repeating section. Please help.

     

    Thanks, 

    Kishu11

  • 08-10-2012 02:11 PM In reply to

    • brianf
    • Not Ranked
    • Joined on 08-10-2012
    • Posts 1

    Re: Deleteing from repeating group on changing event of another field

    did you ever get a resolution to this?  I am having the same issue.  Thanks.
  • 08-13-2012 07:21 AM In reply to

    Re: Deleteing from repeating group on changing event of another field

    No, I still haven't. I noticed that it only happens when a field is inside a repeating section. Hopefully someone from here can help us with this. :S

  • 09-09-2012 05:05 PM In reply to

    • petrel
    • Not Ranked
    • Joined on 09-09-2012
    • Posts 1

    Re: Deleteing from repeating group on changing event of another field

    I am having the same problem. Is there a solution?
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.