0

What could be wrong with this code? I'm fairly new to javascript and I've been trying to debug on my own to no avail.

The alert('confirmed: ' + records[i].ENQ_Confirmed_with_Enbridge__c); shows false but it won't pass the if condition so my counter isn't incrementing.

Same goes with if(records[i].ENQ_QSC_Notified__c === false even if the value of the field is false, it doesn't pass the condition as well.

var assPac = new sforce.SObject("ENQ_Assignment_Package__c"); 
var qscContact = '{!ENQ_Assignment_Package__c.ENQ_QSC_Contact__c}'; 
var status = '{!ENQ_Assignment_Package__c.ENQ_Status__c}'; 
var otherP = sforce.connection.query("Select 
              Id,ENQ_Confirmed_with_Enbridge__c,ENQ_QSC_Notified__c FROM 
              ENQ_QSR_Assignment__c where ENQ_Assignment_Package__c = 
              '{!ENQ_Assignment_Package__c.Id}'");
var records = otherP.getArray("records");

for(var i=0; i<records.length; i++){
alert('confirmed: ' + records[i].ENQ_Confirmed_with_Enbridge__c);
if(records[i].ENQ_Confirmed_with_Enbridge__c === false){
   alert('check');
   counter++;    
}
 alert('counter: ' + counter);
if(records[i].ENQ_QSC_Notified__c === false){
   records[i].ENQ_QSC_Notified__c = true;
   qscNotified.push(records[i]);
}

}
alert('qscNotified: ' + qscNotified.length);

Any help would be appreciated.

1

You should be using getBoolean if you want to do a direct comparison:

if(records[i].getBoolean('ENQ_QSC_Notified__c') === false){

I'd probably recommend this approach for most normal situations.

0

I figured it now with the help of reading this related question(Is there a bug in the way custom buttons handle checkboxes on related objects?). So the boolean has to be enclosed in quotes, where I'm not used to. That was difficult to debug, though.

  • 1
    That is simply because you're getting a string representation of the result in your return from the apex. SFDCFox answer willl work great as it converts the string value to an actual boolean and compares to a boolean. Both approaches will work - however i must agree with his route being cleaner and less prone to error. – Ronnie Oct 20 '17 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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