2016-12-16 1 views
0

Может ли кто-нибудь сказать мне, что CRM будет ненавидеть об этой функции onload, которую я создал?CRM 2016 не нравится Javascript, используя if-else

Это говорит мне, что Form_OnLoad не определен. Выяснилось мне. Он включен в мою форму onload, опубликован и т. Д.

Спасибо.

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()); 
    } 
} 
+0

Это javascript? – philantrovert

ответ

2

Я верю, потому что ваш JavaScript неверен. Попробуйте использовать следующий код вместо вашего:

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()); 
    } 
} 
+0

Спасибо, Андриан. Я думаю, что вижу ошибку в моем коде, где я пытался сделать и без права() и ===. Я больше не получаю ошибку скрипта. Ценить это. Одно дополнение - если я хочу проверить не null * или * = 0, знаете ли вы, как я бы это отрегулировал? –

+0

Если вы хотите проверить бот, вы можете сделать следующее: var a = Xrm.Page.getAttribute ("name"). GetValue(); if (a! = null && a! = 0) {// ваша логика} –

+0

Еще раз спасибо Andrii –

Смежные вопросы