Deleting empty rows from a button inside a repeating table - InfoPath Dev
in

InfoPath Dev

Deleting empty rows from a button inside a repeating table

Last post 05-24-2013 03:31 PM by Ravik. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 05-22-2013 04:21 AM

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Deleting empty rows from a button inside a repeating table

    The issue that I am facing trying to delete empty rows in a repeating table. The scenario is, the user creates empty rows(blank) in the attachment field before inserting an attachment to the field (e.g : 3 blank rows and 4th one has a document attachment) which is inside a repeating table. I have an upload button, which not only uploads the document but also deletes any empty attachments. The problem that I am facing now is, when a user clicks the upload button on the 4th attachment field, the whole lot gets cleared including the last attachment. Please see the attachment for code. Hoping somebody would shed some light to this issue.. Many Thanks
  • 05-22-2013 10:46 AM In reply to

    Re: Deleting empty rows from a button inside a repeating table

     I would loop through this iterator:

    XPathNodeIterator caseAttachments = this.MainDataSource.CreateNavigator().Select("/my:myFields/my:Details/my:Attachment", NamespaceManager);

    And, actually, I'm guessing the repeating group is Details? So, I'd likely do something like this - get the repeating group

    XPathNodeIterator details= this.MainDataSource.CreateNavigator().Select("/my:myFields/my:Details", NamespaceManager);

    foreach(XPathNavigator detail in details)

    {   
         //check to see if attachment is blank - if so, delete row, if not, upload
    }

    DeleteSelf will pitch you out of the loop tho - so you'll want to create a list of the items you wish to delete and then iterate through that to do your actual deleting. Here's a Stack Overflow thread that may help: http://stackoverflow.com/questions/2524986/delete-remove-node-from-xpathnodeiterator-given-an-xpath

    Hilary Stoupa

  • 05-23-2013 05:28 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

    Hi Hilary(Guru)! Thank you very much for your comments, you did really solve my issue. Never knew that DeleteSelf() would pitch me out the loop. All i did was took away this piece of code, because the next code i wrote was clearing away the rows anyway. // took this code away else { WriteToDebug("Removing empty attachment"); caseAttachments.Current.DeleteSelf(); } Thanks again. Well i still have only one major issue which is a blocker. Hoping to get some advice. Ok here it goes. The Infopath form that i had created has about 10 different case types. The Problem that i am facing is Auto- numbering each types. For ex . When the starts a new case they have an option to choose the case they wanted to raise .Case ID should look like Case Type+ ID (GEN-000001), and when the user creates another case in GEN the ID should look like (GEN-000002) but instead it is like (GEN-000039) and so on... because i have 10 different case i want all of them to have a sequential order in ID. For ex. when the chooses a different case, say CCF even though it starts with (CCF- 000001) but the very next case will have an all together different ID such as (CCF-000040). How can i have each case types to generate ID's sequentially? Cant find this type of an issue in any article that i have looked in to. The following is the calculated value which is in a rule that i use to generate an ID each time i click on a Save Case button. I have a field called CaseCount which gets the ID from a DataConnection the calculated value looks like this count(ID[contains(_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_, Type)]) Then i created another field called TempCaseId and set its value as concat(my:Details/my:Type, "-", "000001") I have then created three action rules for the Save Case button 1. Lookup Cases: which queries the data connection 2. Set First Case ID : condition is CaseId is blank and CaseCount 0 which runs the following actions A) Queries the data connection B) Sets Fields Value : TempCaseID and its Value as With Xpath concat(my:Details/my:Type, "-", substring("000000", 1, (6 - string-length(xdMath:Max(xdXDocument:GetDOM("Case Lookup")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[contains(../d:_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_, xdXDocument:get-DOM()/my:myFields/my:Details/my:Type)]) + 1))), xdMath:Max(xdXDocument:GetDOM("Case Lookup")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID[contains(../d:_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_, xdXDocument:get-DOM()/my:myFields/my:Details/my:Type)]) + 1) Without Xpath concat(Type, "-", substring("000000", 1, (6 - string-length(max(ID[contains(_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_, Type)]) + 1))), max(ID[contains(_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_, Type)]) + 1) Not sure what i am doing wrong here. I'll be very grateful if you could help me with this issue. Many Many Thanks Hilary.
  • 05-23-2013 05:34 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

    sorry about the above format..will post another one
  • 05-23-2013 05:47 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

    Sorry about the text in my previous reply. Please see the attached Zip file which has Word document. Thanks
  • 05-23-2013 10:22 AM In reply to

    Re: Deleting empty rows from a button inside a repeating table

    The forum is not always respectful of formatting - it can be rather fussy.

    What you probably need to do is get a count of the cases with the same prefix - GEN, for example. I put together a simple sample form - save it locally, right click and select design and then preview to see the formula in action.

    Hilary Stoupa

  • 05-24-2013 08:58 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

    Hi Hilary, Please see the attached document. Thanks
  • 05-24-2013 09:33 AM In reply to

    Re: Deleting empty rows from a button inside a repeating table

     In my secondary data source, I have two pieces of information - the ID of the item and item name (which contains the prefix needed for the more complex XPath filter). In your secondary data source, I just see the ID. You should also include the info from your list that indicates the type.

    Hilary Stoupa

  • 05-24-2013 10:53 AM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

    Hi hilary, please see the attached. Thanks.
  • 05-24-2013 12:00 PM In reply to

    Re: Deleting empty rows from a button inside a repeating table

     Hi - so your screenshot shows that you now have the Case Id in the data source - does that contain the info that you need? Is Case Id going to be "GEN-000002" and so on? Can you just attach your template so I can help w/ the formula? If not, can you copy the XPath for the new field of Case Id in your secondary data source and paste in a reply?

     

    Hilary Stoupa

  • 05-24-2013 03:31 PM In reply to

    • Ravik
    • Top 500 Contributor
      Male
    • Joined on 01-25-2013
    • Aberdeen(Scotland)
    • Posts 33

    Re: Deleting empty rows from a button inside a repeating table

     Hi Hilary,

    The size of my form template is 650kb, as much as I wanted to share it with you(My Guru:)) and get a feedback of my very first project in InfoPath. One thing that, I truly have to admit is that without the guidance that I had over the course of time from you and from the InfoPath dev team, I wouldn't have come anywhere near to the end of my project. Well I still need your help :) to complete it. Please see below the XPath of caseId as requested

     

    /dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:_x007b_2a9d2794_x002d_aeb9_x002d_4dcf_x002d_993f_x002d_4303298d5a7c_x007d_

    Thanks

    Regards,

    Ravi

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