user290687
user290687

Reputation: 87

Nested If Not Running Else

I'm trying to evaluate a couple of things. I'm pasting the code from the first parent if statement and the nested if/else. For some reason when a condition is met for the parent it always uses the nested if instead of going to the else. Even if it does not meet the if criteria it still runs that piece of the code.

var setmeow = new Date();
var meow = nlapiDateToString(setmeow);
if(!Result[i].getValue('custcol_ram_billing_end_date') ){
    var edpb = Result[i].getValue('custcolram_last_rental_billed')
    if(edpb != null || edpb != ' ') {                       
        var daysbetwenced = days_between(nlapiStringToDate(Result[i].getValue('custcol_ram_billing_start_date')), setmeow);
        record.setCurrentLineItemValue('item', 'quantity', daysbetwenced+1);
        //record.setCurrentLineItemValue('item', 'custcol_ram_billing_start_date', Result[i].getValue('custcol_ram_billing_start_date'));
        record.setCurrentLineItemValue('item', 'custcol_ram_billing_end_date', meow);
        record.setCurrentLineItemValue('item', 'custcolram_last_rental_billed', meow);
    } else {
        var daysbetweennoend = days_between(nlapiStringToDate(Result[i].getValue('custcolram_last_rental_billed')), setmeow);
        record.setCurrentLineItemValue('item', 'quantity', daysbetweennoend+1);
        record.setCurrentLineItemValue('item', 'custcol_ram_billing_start_date', Result[i].getValue('custcolram_last_rental_billed'));
        record.setCurrentLineItemValue('item', 'custcol_ram_billing_end_date', meow);
        record.setCurrentLineItemValue('item', 'custcolram_last_rental_billed', meow);
    } 
}

Upvotes: 0

Views: 59

Answers (1)

Pointy
Pointy

Reputation: 413757

Keeping in mind that || is the logical-OR operator (kind-of),

if(edpb != null || edpb != ' ')

Whatever edpb is, it will always be either not equal to null or not equal to ' '. That is, it will either be neither null nor ' ', or else it will be one of them and not the other.

Maybe what you really want is to perform the if part if edpb is not either null or ' ', which would be:

if (edpb != null && edpb != ' ')

Upvotes: 1

Related Questions