Current and Position ---- always one (1) ? - InfoPath Dev
in

InfoPath Dev

Current and Position ---- always one (1) ?

Last post 02-02-2011 11:49 AM by Maureen57. 18 replies.
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts: Previous Next
  • 01-16-2011 10:02 AM

    Current and Position ---- always one (1) ?

     I have a form with a header section and then a repeating child section.  The repeating child section is attached to a secondary data connection, and there is a button on it.

     That button needs to send an email through a web service to the current email address in the secondary data connection.

     It also needs to update a database with the current instance, through code.

     I just discovered that current is always evaluating to one.    Put some text boxes at the header and the detain level, which calculate  Count and Position.

     Count is right, it will count the number of detail records; but Position is ALWAYS 1.

    This is Infopath 2007. 

     

     

     

  • 01-16-2011 10:03 AM In reply to

    Re: Current and Position ---- always one (1) ?

     

  • 01-16-2011 06:34 PM In reply to

    Re: Current and Position ---- always one (1) ?

    I looked at your form, but I don't see what you're trying to accomplish with position().  The way you have it there, yes, it will always evaluate to 1. position() is typically used in filtering XPath expressions, and evaluating its value does not usually yield a meaningful result.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-17-2011 05:07 AM In reply to

    Re: Current and Position ---- always one (1) ?

     What I'm trying to do is use the current values in the repeating group to send an webservice email (action on the last button) and to update a database with code (on the last button).

     What I get is always the first member of the repeating group, when I use the current function.    Current is always equal to one, even when my cursor is positioned in the last instance of the repeating group.

     I only added the calculated fields with position to the screen to see if the form ever knows any current value other than 1.  May be incorrect debugging technique, if position does not evaluate to current.  The first button on the repeating group, when pushed, also displays position () in one of the datasource fields.  It is always equal one.   

     The problem is that I always get one for the expression current.

  • 01-17-2011 05:44 AM In reply to

    Re: Current and Position ---- always one (1) ?

    By "Current" do you actually mean where the cursor is, or the last row of the repeating table.

     If you mean the last row of the repeating table, you have to use the 'last()' command in the x-path.

    Ex: /my:myFields/my:NameOfGroup/my:NameOfRepeatingTable[last()]/my:NameOfField

    Name Number
    Item 1 1
    Item 2 2
    Item 3 3

    To get the last of Number from this table, it would be: /my:myFields/my:Group1/my:ItemTable[last()]/my:Number

    The my namespace, myFields and Group1 can be different depending on you setup your fields.

     

    If you are trying to get the true current(where the cursor is) value, I don't think it possible.

     

    GMoore

     

  • 01-17-2011 05:44 AM In reply to

    Re: Current and Position ---- always one (1) ?

    position() and current() just don't work like that.

    You should be able to use this formula in your button's rule to determine the row number where that button was clicked.

    count(preceding-sibling::vw_Fedex_SPOD_N)

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-17-2011 05:57 AM In reply to

    Re: Current and Position ---- always one (1) ?

     Thank you, will try....

  • 01-18-2011 08:50 AM In reply to

    Re: Current and Position ---- always one (1) ?

    Many thanks for your help ---

    I created a button inside my repeating section, added one rule - to set a fields value to count(preceding-sibling::vw_Fedex_SPOD_N)

    Then, I previewed the form. There were three instances of the repeating section.

    I clicked the button in instance 1 - field value set to 1.

    I clicked the button in instance 2 - field value set to 1.

    I clicked the button in instance 3 - field value set to 1.

     What am I doing wrong?   How do I get the current instance number?

  • 01-18-2011 09:38 AM In reply to

    Re: Current and Position ---- always one (1) ?

    Could you post your form here again with those modifications?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-18-2011 10:15 AM In reply to

    Re: Current and Position ---- always one (1) ?

     Here it comes --- the DUMMY button is the one with the new rule, setting the ID field to count(preceding-sibling::vw_Fedex_SPOD_N)

  • 01-18-2011 10:28 AM In reply to

    Re: Current and Position ---- always one (1) ?

    Your button rule is setting the field to the string value "count(preceding-sibling::vw_Fedex_SPOD_N)".  You need to use the formula editor dialog.  I was mistaken in the formula I gave.  It should be:

    count(preceding-sibling::d:vw_Fedex_SPOD_N) + 1

    The reason the field is always showing 1 is that you have a rule on the field that sets itself to the value of count(.) (which is always 1) when its value is modified.  You need to disable that rule.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-18-2011 10:45 AM In reply to

    Re: Current and Position ---- always one (1) ?

     It worked ---- !!!!!!!   Thank you thank you.

  • 01-18-2011 10:46 AM In reply to

    Re: Current and Position ---- always one (1) ?

     THANK YOU!

  • 01-18-2011 07:23 PM In reply to

    Re: Current and Position ---- always one (1) ?

    The reason I needed to find the current member of the group is because when I used this statement in the button code, it always pulled the first instance of d:vw_Fedex_SPOD_N

    trackingnum = eventObj.Source.selectsingleNode("/dfs:myFields/dfs:dataFields/d:vw_Fedex_SPOD_N/@TrackingNumber").text;

    (Not sure why that didn't get the current instance. Everything I read said it would....)

    Now (thanks to you), I have a number on the form that evaluates correctly to the current instance index. The index variable is instance_nbr, and it does evaluate correctly to the current instance of d:vw_Fedex_SPOD_N in the button code.

    var nodesDetail = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:vw_Fedex_SPOD_N");

    var row = nodesDetail.item(instance_nbr);

    trackingnum = row.selectSingleNode("@TrackingNumber").text

    But the last statement throws an error - null is null or not an object.

     How can I use this index to load  the correct instance values into fields?

     

    THANK YOU 

     

     

     

  • 01-18-2011 08:32 PM In reply to

    Re: Current and Position ---- always one (1) ?

    The reason Source isn't doing what you expect is that you're using absolute XPaths.  You need to use relative XPaths.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 2 (19 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.