What's wrong with this if else statement? - InfoPath Dev Sign in | Join | Help in Code 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 » Code » What's wrong with this if else statement? What's wrong with this if else statement? Last post 09-26-2006 05:31 PM by cornik99. 6 replies. Page 1 of 1 (7 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 09-15-2006 05:09 PM cornik99 Joined on 09-06-2006 USA Posts 13 What's wrong with this if else statement? Reply Contact Codes run okay when sourcePhDirect <> null but when it's blank the value of sourceExt is being returned as null even though it has a value. This for the business card order form where the phone value is fill-in from another form using the direct line number but if an employee doesn't have one then it's the company main number plus the extension.var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");if (sourcePhDirect != null) destPhone.text = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct").text;else destPhone.text = "(555)-201-8000 x" + XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext").text; 09-20-2006 12:09 AM In reply to nukkumatti Joined on 12-08-2005 Germany Posts 349 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact Can you try (sourcePhDirect != "") instead of if (sourcePhDirect != null). Listen to Motörhead cos they play Rock'n Roll :) 09-21-2006 12:26 AM In reply to Shiva Joined on 04-15-2005 India Posts 694 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact Hi Cornik,Can you try for one more condition,if (sourcePhDirect != undefined) Shiva / http://www.ggktech.com 09-21-2006 12:35 AM In reply to nukkumatti Joined on 12-08-2005 Germany Posts 349 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact And please let us know what resolved your issue. Listen to Motörhead cos they play Rock'n Roll :) 09-21-2006 10:10 AM In reply to Greg Collins Joined on 08-07-2006 Posts 2,126 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact Checking for null is correct assuming that you expect the node to be physically not present in the DOM at times. If you want to know whether it is blank... that's different.Also, you don't need to reselect the field multiple times as you've already stored it in a variable.Try:1. For node to be physically not present:var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");if(sourcePhDirect != null) destPhone.text = sourcePhDirect.text;else destPhone.text = "(555)-201-8000 x" + sourceExt.text;2. For node value being blank:var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");if(sourcePhDirect.text != "") destPhone.text = sourcePhDirect.text;else destPhone.text = "(555)-201-8000 x" + sourceExt.text;3. For node being either not present or blank:var sourcePhDirect = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_direct");var sourceExt = XDocument.DOM.selectSingleNode("//my:myFields/my:telephone_ext");if(sourcePhDirect.text != null && sourcePhDirect.text != "") destPhone.text = sourcePhDirect.text;else destPhone.text = "(555)-201-8000 x" + sourceExt.text; Please Visit:BraintroveGreg's Paintings 09-26-2006 05:09 PM In reply to cornik99 Joined on 09-06-2006 USA Posts 13 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact Thank you all for your help but the one that worked was Greg's solution #3 (For node being either not present or blank). Greg, you're great! Sorry, I was sick so I wasn't able to respond right away. 09-26-2006 05:31 PM In reply to cornik99 Joined on 09-06-2006 USA Posts 13 Re: What's wrong with this if else statement? Mark as Not AnswerMark as Answer... Reply Contact I have another issue with if else on opening another form which I started on new thread .open another form using if else condition'. So, please help me again. Thanks. Page 1 of 1 (7 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.