We help IT Professionals succeed at work.

Problem evaluating javascript equality expression

-Dman100-
-Dman100- asked
on
67 Views
Last Modified: 2017-04-06
I am having an issue with the following javascript expression:
}else if(prnPosition == "Yes" && urgentCare && currentDate.getTime() < startDatePlus90Days.getTime()){
alert("We are in the 90 day branch");
}else if(prnPosition == "Yes" && currentDate.getTime() < startDatePlus180Days.getTime()){
alert("We are in the 180 day branch");
}else if(...

Open in new window


When the prnPosition is true and urgentCare is false and currentDateTime is less than the startDatePlus90Days it still goes into the 90 day branch. I would expect the code to bypass the 90 day branch and enter the 180 day branch.

It seems like something simple, but I'm not seeing why the code flows into the 90 day branch if the urgentCare variable value is false.  Do I need to explicitly say:

urgentCare == true

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Set currentDate.getTime  between 90 and 180 days
currentDate.getTime() >= startDatePlus90Days && currentDate.getTime() < startDatePlus180Days

Open in new window

CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
I forgot to add .getTimes() after the starDatePlus90.... etc
-Dman100-Software Consultant

Author

Commented:
Thanks for the quick reply. I'm still not clear on the check for between the 90 and 180 days. If the variable currentCare is false in that first branch, should it not immediately bypass the first branch and go into the 180 day branch regardless? I have a false in that first branch and I would expect that it would fall into the next branch (180 days). Is that not correct?
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
You have right...I think that there is a variable that makes the code to run in a wrong way. Can you post all the code?
-Dman100-Software Consultant

Author

Commented:
Hi Leonides,

Here is the full code. I k now it is a bit messy.

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}

var referral = "{!Referral__c.Id}"
var status = "{!Referral__c.Status__c}";
var provider = "{!JSENCODE(Referral__c.Provider__c)}";
var reported = "{!Referral__c.Reported_Date__c}";
var signedDate = "{!Referral__c.Contract_Signed_Date__c}";
var startDate = "{!Referral__c.Contract_Start_Date__c}";
var contractType = "{!Referral__c.Contract_Type__c}";
var prnPosition = "{!Referral__c.PRN_Position__c}";
var contractAssist = "{!Referral__c.Contract_Assist__c}";

var currentDate = new Date();
var startDatePlus180Days = new Date(startDate).setDate(new Date(startDate).getDate() + 180);
var startDatePlus90Days = new Date(startDate).setDate(new Date(startDate).getDate() + 90);
startDatePlus180Days = new Date(startDatePlus180Days);
startDatePlus90Days = new Date(startDatePlus90Days);

NPDB = sforce.connection.query("SELECT Id, Provider__c FROM Quality_Check__c WHERE Provider__r.Name = '{!JSENCODE(JSENCODE(Referral__c.Provider__c))}' AND Quality_Check_Type__c='NPDB Received' ");
disclosure = sforce.connection.query("SELECT Id, Provider__c FROM Quality_Check__c WHERE Provider__r.Name = '{!JSENCODE(JSENCODE(Referral__c.Provider__c))}' AND Quality_Check_Type__c='Disclosure Forms Received' ");
reference = sforce.connection.query("SELECT Id, Provider__c FROM Quality_Check__c WHERE Provider__r.Name = '{!JSENCODE(JSENCODE(Referral__c.Provider__c))}' AND Quality_Check_Type__c='Reference Received' ");
background = sforce.connection.query("SELECT Id, Provider__c FROM Quality_Check__c WHERE Provider__r.Name = '{!JSENCODE(JSENCODE(Referral__c.Provider__c))}' AND Quality_Check_Type__c='Background Check Received' ");

var entity = sforce.connection.query("SELECT Entity_Name__r.Urgent_Care__c from Referral__c where Id = '{!Referral__c.Id}'");
var entityArray = entity.getArray("records");
var urgentCare = entityArray[0].Entity_Name__r.Urgent_Care__c;

alert(prnPosition);
alert(urgentCare);
alert(currentDate.getTime());
alert(startDatePlus90Days.getTime());

if(status != "Signed" )
{
alert('Referral Status must equal Signed to create a Bonus');
}else if(disclosure.size<1 && (contractType == "HCA Employed / 501A" || contractType == "PRN" || contractType == "Financial Assistance" )){
alert('Please attach Disclosure Quality Check to Provider');
}else if(reference.size<1 && (contractType == "HCA Employed / 501A" || contractType == "PRN" || contractType == "Financial Assistance" )){
alert('Please attach References to Provider');
}else if(background.size<1 && (contractType == "HCA Employed / 501A" || contractType == "PRN" || contractType == "Financial Assistance" )){
alert('Please attach Background Check, Quality Check to Provider');
}else if(NPDB.size<1 && (contractType == "HCA Employed / 501A" || contractType == "PRN")){
alert('Please attach NPDB Received Quality Check to Provider');
}else if(reported == ""){
alert('Please enter a Reported Date');
}else if(signedDate==""){
alert('Please enter a Contract Signed Date');
}else if(startDate ==""){
alert('Please enter a Contract Start Date');
}else if(prnPosition == "Yes" && urgentCare && currentDate.getTime() < startDatePlus90Days.getTime()){
alert("We are in the 90 day branch");
alert('You are attempting to submit a bonus for an urgent care PRN Provider. Bonuses are paid 90 days after the provider starts practicing. Please submit the bonus at that time.');
}else if(prnPosition == "Yes" && currentDate.getTime() < startDatePlus180Days.getTime()){
alert('You are attempting to submit a bonus for a PRN provider. Bonuses are paid 180 days after the provider starts practicing. Please submit the bonus at that time.');
}else if(contractAssist == "Yes"){
alert('Contract assists are not eligible for a bonus');
}else{
window.location.href="/apex/BonusStep0?referralid={!Referral__c.Id}";
}

Open in new window

-Dman100-Software Consultant

Author

Commented:
Looks like the value returned is interpreted as a string? If I change my evaluation to the following it works:

if(urgentCare == "true")

Open in new window


Why?
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
-Dman100-Software Consultant

Author

Commented:
Thank you!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.