I am trying o check a field weather it is null or not but in a javascript snippet

  • 1
  • Problem
  • Updated 3 years ago
  • Not a Problem
Every time the if block of code is getting executed even if the condition is false .
I think the problem lies in  null checker line 
Here is the code-

var applicationModel = skuid.model.getModel('Application');//alert("applicationModel "+applicationModel);
var applicationRow =  applicationModel.data[0];
//alert("applicationRow "+applicationRow);
var appId =applicationRow.Id;
//alert("applicationRow.Id   "+ applicationRow.Id);
var stat=applicationRow.genesis__Status__c;
//alert("stat "  +stat);
var ad=applicationRow.genesis__Auto_Decisioning__c;
alert("autodecisioning  "  +ad);
var lending_product=applicationRow.genesis__Lending_Product__c;
alert("lending_product "  +lending_product);
var newstat="NEW - PRICING GENERATED";
//alert("newstat   "  +newstat);
var newstat2="APPROVED - CONVERTED TO CONTRACT";
var agree = confirm("Are you sure ?");
if (agree){
    
    if (stat.toUpperCase() == newstat2)
    {
         alert("Application is alerady Converted ");
    }
    
    else if (stat.toUpperCase() == newstat)
    {
         
if((ad === true) )
{
 
if(lending_product !=='null' )              // this condition is failing.
{ var retVal = sforce.apex.execute("DemooOrgUtils","borrowerAccepted",{app:appId}); 
    alert('retVal'+retVal);  
    window.location.reload();
   

}
else{
  
   
alert("--Please insert a lending product-- ");

}

}
else{
alert("--Please enable Auto Decisioning-- ");
}
    }
    else
    alert("----Please generate pricing----  ");
    }
    

In alert lending_product shows 'undefined' but it contains null .So i am not sure what needs to be checked there .So I am now stuck here.
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
I assume that genesis__Lending_Product__c is part of your model -- correct?

Have you tried changing the code to 
if (lending_product ) { ... }
else { alert("--Please insert a lending product-- "); }
- or - 
if (lending_product !== undefined && lending_product !== null) {
   // lending_product has a value
} else {
   alert("--Please insert a lending product-- ");      
}