If else statement error in jscript. PLEASE HELP!

D

danlin99

Please help me find what the problem with this if statement is? I have spent
2 days trying to fix it but still nothing. Thanks in advance.

The codes below will not open the business card form with either false and
true value if I have the '== true'
************************************************************
var sourceBusinessCard =
XDocument.DOM.selectSingleNode("//my:myFields/my:business_card_yes_no").text;

//business card order is checked
if (sourceBusinessCard == true)
{
//open business card template
var xBusCard =
Application.XDocuments.NewFromSolution("\\\\everest\\public\\forms\\Infopath
Business Card Order Form.xsn");
}
********************************************************


The codes below open the business card form with both false and true value
if I have the '= true'
************************************************************
var sourceBusinessCard =
XDocument.DOM.selectSingleNode("//my:myFields/my:business_card_yes_no").text;

//business card order is checked
if (sourceBusinessCard == true)
{
//open business card template
var xBusCard =
Application.XDocuments.NewFromSolution("\\\\everest\\public\\forms\\Infopath
Business Card Order Form.xsn");
}
********************************************************
 
G

Greg Collins [InfoPath MVP]

You are getting a text value, not a boolean value. Your if-statement needs to be checking for a text value:

if(sourceBusinessCard == "true")
 
D

danlin99

I tried it Greg but I'm the if statement runs no matter what the value of the
variable is. Can you please see if you can duplicate my problem by creating
two separate forms? Add business_card_order (boolean) field to Form1. Next,
create a button and type your if and else statement to open form2 if the
value of business_card_order is equal to true else do something else. I
asked my coworkers to check the codes and they cannot see what the problem
is. I hope this is not a bug.
 
G

Greg Collins [InfoPath MVP]

One other thing to check is what values your boolean is actually storing. Note the name of the field:

my:business_card_yes_no

This might indicate that your field stores boolean values as "yes" and "no" rather than "true" and "false". Or maybe it stores them as "1" and "0".

Please verify what values are being stored... and then again, since you are getting a text value, compare against a text value:

== "yes"
== "true"
== "1"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top