XPath equivalent of IF Function? - InfoPath Dev Sign in | Join | Help in Newbie Questions InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Newbie Questions » XPath equivalent of IF Function? XPath equivalent of IF Function? Last post 02-16-2007 10:54 AM by Greg Collins. 9 replies. Page 1 of 1 (10 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 02-13-2007 08:51 AM funniegrrl Joined on 02-13-2007 Posts 18 XPath equivalent of IF Function? Reply Contact Hi there --I'm relatively new to InfoPath and brand-new to XML/XLT/XPath, whathaveyou. I have a form in which I'm trying to compare two fields, and, based on the result, display one or the other. In Excel I'd write the statement like this:=IF(fielda<fieldb,fielda,fieldb)In other words, if “fielda” is smaller than “fieldb”, then display the contents of “fielda” otherwise display “fieldb”.For the life of me I can't figure out how to do this with the available XPath functions. Can anyone offer assistance? 02-13-2007 09:49 PM In reply to Shilpa Pitta Joined on 06-05-2006 India Posts 101 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Hi and welcome to the forums, This we can do using rules in the Infopath and bu using XPath functions, string value1=thisXDocument.Dom.selectsinglenode(XPath1).text; string value2=thisXDocument.Dom.selectsinglenode(XPath2).text; if(value1 < value2) { print(value1); } else { print(value2); } Shilpa INFOPATHDEV India 02-14-2007 12:57 PM In reply to Greg Collins Joined on 08-07-2006 Posts 2,126 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Sounds like what you need is conditional formatting.Have both fields present in the view. Then add conditional formatting to fielda which hides it if its value is greater than or equal to the value in fieldb. Add conditional formatting to fieldb which hides it if its value is greater than fielda. Please Visit:BraintroveGreg's Paintings 02-14-2007 01:09 PM In reply to funniegrrl Joined on 02-13-2007 Posts 18 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Hi Greg --That's a good idea, but the data has to actually be used elsewhere, it's not just about hiding the one that's larger. The outcome of this function would be part of a rule about the contents of a 4th field.Shilpa, I appreciate your help. I'm not a programmer and I don't know anything about nodes, etc., so I'm not sure what to do with what you've provided. What is a placeholder for my info, what needs to be copied verbatim? And, where do I enter this? In the Display option in that field's dialog box, using the fx button? 02-14-2007 11:37 PM In reply to Shilpa Pitta Joined on 06-05-2006 India Posts 101 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Hi,I had a question to you-compare two fields, and, based on the result, display one or the other. The outcome of this function would be part of a rule about the contents of a 4th field.Is this what you want?Is there any field that display according to the condition for fielda and fieldb? or is that only field4? Shilpa INFOPATHDEV India 02-15-2007 11:03 AM In reply to Greg Collins Joined on 08-07-2006 Posts 2,126 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Maybe I don't understand your scenario well enough... but you mentioned using "part of a rule". I take that to mean that are using the Rules feature available on fields. If that is the case, there is a condition portion of a rule that must be met before any actions occur. It is there that you can do your if/else. Just make sure that on the if(true) portion of the condition, you check the box to stop running rules (at the bottom of the dialog), and then you can do the same thing on the if(false) portion of the rule. Please Visit:BraintroveGreg's Paintings 02-15-2007 12:33 PM In reply to funniegrrl Joined on 02-13-2007 Posts 18 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Hi, thanks for trying to help! Here's some more information, and where I stand now. The first field is a drop-down called budget. Based on the choice made in this field, a second field, budget_ind, is populated with a number using rules set up on budget. There is conditional formatting on budget_ind which changes the color of the field: 1=red, 2=yellow, 3=green, 4=blue.The third field is roi, and it works in the same way, populating roi_ind, which has the same conditional formatting setup.The fifth field is budget_total which is a cumulative indicator, if you will. This is the field whose value I was trying to set with a function. What I've done now is set up rules on roi_ind which state:If roi_ind is smaller (worse) than budget_ind, then use the value of roi_ind. If roi_ind is larger than budget_ind, then use the value of budget_ind. Basically, whichever of the two is smaller trumps the other.So, this setup works, EXCEPT ...If the user makes a selection in both budget and roi, then CHANGES one or the other or both, budget_total does not update to reflect the possible new value. Whatever the result of the rules was after the first selection in each field remains and doesn't refresh.If I could go with my original plan of using a function, I'm assuming that it would do what I need because I could check the "Update this value ..." checkbox under the Default Value field in the Properties box. So, any help on using either the function OR my current rules-based setup would be much appreciated. 02-15-2007 03:40 PM In reply to Greg Collins Joined on 08-07-2006 Posts 2,126 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Sounds like you are 99% of the way there. Have patience and hope!Your rules on roi_ind sound like they are working correct. However you are having a problem where if the user updates budget, which updates budget_ind, then budget_total doesn't get updated.This is easily rectified by adding the same rules to budget_ind as you have on roi_ind. Why do you have to duplicate this? Because rules fire when a value is changed. So right now when roi is changed, it updates roi_ind. Now that roi_ind has changed, it updates budget_total. However, if you update budget, it updates budget_ind, which unfortunately doesn't have any rules yet to update budget_total.So the solution (which you almost had) is to make sure that both _ind field have the same rules to update the _total field.Great job! Let me know how it works out! Please Visit:BraintroveGreg's Paintings 02-16-2007 07:21 AM In reply to funniegrrl Joined on 02-13-2007 Posts 18 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Genius! Sheer genuius! It works like a charm. I had actually thought about trying that, but then assumed it would be unnecessary overkill. That'll teach me! heh hehThanks, Greg, I really appreciate the help. Saved the day! 02-16-2007 10:54 AM In reply to Greg Collins Joined on 08-07-2006 Posts 2,126 Re: XPath equivalent of IF Function? Mark as Not AnswerMark as Answer... Reply Contact Glad to have helped out. Its the process of learning. It won't be long before you'll be answering everybody's questions about InfoPath!! Please Visit:BraintroveGreg's Paintings Page 1 of 1 (10 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.