Daniel San
Daniel San

Reputation: 3

CRM 2016 not liking Javascript using if-else

Can anyone tell me what CRM would hate about this onload function I've created?

It's telling me Form_OnLoad is not defined. Looks defined to me. It's enabled in my form onload, published, etc.

Thank you.

function Form_OnLoad() {
    //Calculates total commission for AE1

    // Products + Services
    if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
        var comm1 = (Xrm.Page.getAttribute("new_commissionproductae1").getValue() + Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(comm1);   
    } else if {
    // Products only
    (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionproductae1").getValue());  
    } else if {
    // Services only
    (Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());  
    } else {
    // Net Sales 
    (Xrm.Page.getAttribute("new_commissionnetae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());  
    }
}

Upvotes: 0

Views: 1771

Answers (1)

Andrew Butenko
Andrew Butenko

Reputation: 5456

I believe that's because your JavaScript is not correct. Try to use following code instead of yours:

function Form_OnLoad() { //Calculates total commission for AE1

    // Products + Services
    if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null && 
        Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null && 
        Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
        var comm1 = Xrm.Page.getAttribute("new_commissionproductae1").getValue() + Xrm.Page.getAttribute("new_commissionserviceae1").getValue();
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(comm1);   
    } else if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null && 
        Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionproductae1").getValue());  
    } else if (Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null &&
        Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());  
    } else if (Xrm.Page.getAttribute("new_commissionnetae1").getValue() !== null &&
        Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
        Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());  
    }
}

Upvotes: 2

Related Questions