0

I have an XPath expression that returns true or false (NOT boolean, just strings in a text field).

I would like to set a condition on my target field so that its value varies if this XPath expression is true v. false. I know an InfoPath rule could easly change the field value.

My problem is that despite the XPath returning a string, I cannot seem to evaluate it with an InfoPath rule (EX: TargetField is blank / TargetField is not blank / TargetField is equal to true).

Specific Detail

I have 4 primary fields:

  1. Initial Date value (InitialDate)
  2. Repeating Date value (RepeaterDate - changes appended to the initial form)
  3. XPath expression field that captures prior entry in repeating date value field (listed after sample XML)
  4. XPath expression field to evaluate presence of Repeating Date (returns true or false for present v. not present - listed after sample XML)

The XPath expression (#4 on the list) correctly returns 'true' or 'false'.

XML and XPath Expressions

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.10" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\9016384cab6148f6\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-07T14:19:10" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:InitialSection>
    <my:InitialDate>2012-09-13</my:InitialDate>
</my:InitialSection>
    <my:RepeaterSection>
        <my:RepeaterGroup>
            <my:RepeaterDate>2012-09-14</my:RepeaterDate>
        </my:RepeaterGroup>
        <my:RepeaterGroup>
            <my:RepeaterDate>2012-09-17</my:RepeaterDate>
        </my:RepeaterGroup>
        <my:RepeaterGroup>
            <my:RepeaterDate>2012-09-19</my:RepeaterDate>
        </my:RepeaterGroup>
    </my:RepeaterSection>
<my:DateEval>2012-09-19</my:DateEval>
<my:DateField xsi:nil="true"></my:DateField>
<my:DateEvalBool>true</my:DateEvalBool>

This example XML has several nodes containing revised dates. The DateEval field returns the last date in the repeating list using the following XPath Expression:

//my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate

This value is then evaluated for the presence of text using another XPath expression:

//my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[(text())]

Again, this consistently returns true or false as you can see in the sample XML.

Initial Question

Why is it then that I cannot successfully evaluate this true or false value in a regular InfoPath 2010 field rule?

5
  • Could you share your XSN template (and if it contains code-behind, then VSTA proj also)? Sep 11, 2012 at 7:57
  • I am trying to find a decent spot to host the file (I don't think that StackOverflow/StackExchange allows attachments). In the meantime I asked on StackOverflow and was given the following XPath expression: //my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[(text())] | //my:InitialDate[text() and not(//my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[(text())])] It works well except that whenever I insert a new item in the repeating section this formula (despite being the default value) does not execute.
    – Shrout1
    Sep 11, 2012 at 14:19
  • Gennady, thank you for your help. You seem to be one of the most active users on this forum and I appreciate that. I believe this question may have been too obfuscated and complex to be appropriately answered. I will self answer this question as I believe I have found a solution.
    – Shrout1
    Sep 11, 2012 at 14:31
  • Chris, I simply could not reproduce the template which creates cited XML (in my XML I have a bunch of attributes in XML elements) as well as "Again, this consistently returns...". It is not described where and/or do you use cited XPath expressions... Sep 12, 2012 at 15:25
  • Gennady, thanks again. I would find a host but I have effectively resolved the situation on my own at this point. I truly appreciate your efforts though! Do you have any recommendations as to where I should host my file? Perhaps I should create a StackExchange specific DropBox account.
    – Shrout1
    Sep 12, 2012 at 15:56

1 Answer 1

1

I will answer this question on my own as I determined what was going on.

  • The fundamental issue here was that I needed a rule for each and every location where the "Repeating Date" could be affected. Rules were not sufficient to resolve this issue.
  • It also turned out that rules were not elegant enough to do what everything I need. I needed an XPath expression that contained most of the necessary logic within itself.
  • 'true' and 'false' were being evaluated correctly each and every time. It was simply that the rules were not being applied because the location where the rule resided was not being affected by the operation, thereby never triggering the rule.

Here is the necessary XPath expression that allows for the "RepeaterDate" to use the prior "RepeaterDate" or fall back on the "InitialDate" if a prior "RepeaterDate" does not exist:

//my:RepeaterGroup[1=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[(text())] | //my:InitialDate[text() and not(//my:RepeaterGroup[1=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[(text())])] 
  • It is important that 1=count here such that the new "RepeaterDate" field always evaluates the prior "RepeaterDate". When a new instance of "RepeaterDate" is created it instantly becomes the "Latest" "RepeaterDate". From its perspective it must select the previous repeater date (That means 1 and not 0).
  • ALSO be sure to UNCHECK "Refresh value when formula is recalculated" in InfoPath - this will keep prior instances of "RepeatingDate" from updating to a more recent instance.

To simply return the latest "RepeaterDate" one can use the following XPath expression (note the use of 0=count):

//my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate

The last fundamental "InfoPath Only" component of this puzzle is also somewhat complex. The "InitialDate" field requires the following rule:

  1. Check for the existance of a "RepeatingDate" using the following XPath Expression: //my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:RepeaterDate[not(text())] (I applied this as the default value in a seperate text field)
  2. Create a condition that checks for a "false" return from step #1
  3. If no "RepeatingDate" exists then create an action to set the "RepeatingDate" field equal to the InitialDate field. This will provide the first default value to the user.

From this point forward the "Initial Date" field will always provide the first date to the "RepeatingDate" field. Every new "RepeatingDate" will always default to the "RepeatingDate" value that was listed before it.

Basically, an initial "End Date" or "Due Date" can be suggested on a form. If someone makes an amendment to this form then the initial date will be populated into the amendment field by default. If a second schedule amendment is made it will take into account the first schedule amendment and default to the amended value rather than the initial value. One less thing for the user to screw up.

Thanks again for all the help! The StackOverflow / StackExchange community is AMAZING!!!

3
  • Chris, we will be flagged as offenders by this board software for having discussion which is against the guidelines of this board. One of the google search results for file sharing If you solved your problem and do not want to bother making it helpful (comprehensible, reproducible) to others than you would better delete your question Sep 14, 2012 at 12:07
  • Gennady, I listed a very comprehensive solution to this issue above. I don't mean to violate any rules, I simply don't see the value in adding the XSN template at this point. The issue is truly XPath related and it can be resolved using the source XML I have listed along with the XPath expression I posted. My hope is that this solution will help others resolve this same issue - I don't mean to offend or violate guidelines. I have been truly thankful for the help I have received here at StackExchange.
    – Shrout1
    Sep 14, 2012 at 16:51
  • To appease the gods: Link to the xsn template file. I don't know if it will work or not, I'm using I.E. 8 and I'm not sure my browser it seeing it the right way. Truly hope it helps someone else! If I can ease someone else's troubles then that's what I'm here for.
    – Shrout1
    Sep 14, 2012 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.