2017-07-06 58 views
0

我已經粘貼下面的例子谷歌腳本得到錯誤,而把多個條件

代碼:

function ck() { 

    //assigning variables 

    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getActiveSheet(); 
    var lastrow = ss.getLastRow(); 
    var valsr7 = sheet.getRange(lastrow, 3).getValue(); 
    var valsr30 = sheet.getRange(lastrow, 4).getValue(); 
    var valsrn = sheet.getRange(lastrow, 5).getValue(); 
    var valINC7 = sheet.getRange(lastrow, 6).getValue(); 
    var valINC30 = sheet.getRange(lastrow, 7).getValue(); 
    var valINCn = sheet.getRange(lastrow, 8).getValue(); 
    var service = sheet.getRange(lastrow, 2).getValue(); 
    var now = new Date(); 
    var wk = now.getWeek(); 

    //now assigning values to variable 
    var A = valsr7; 
    var B = valsr30; 
    var C = valsrn; 
    var D = valINC7; 
    var E = valINC30; 
    var F = valINCn; 
    var AB = AB; 

    if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0){ 
    MailApp.sendEmail({ 
    to: "[email protected]", 
    subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"", 
    htmlBody: "Dear ABC, "+ 


    "<p>Not assigned to any one = "+C+""+ 


    "<P>&emsp;&emsp;&emsp;"+" "+ 

    "<p>Not updated more than 7 Days = "+D+" "+ 
    "<p>Not Updated more than 30 Days = "+E+""+ 
    "<p>Not assigned to any one = "+F+""+ 



    "<p>&emsp;&emsp;&emsp;"+" "+ 
      "<p>Best Regards,"+ 
      "<br>Global Service Desk "+, 
    cc: "[email protected]"}) 
    } 

    if(service == 'Global-Servicenow-Support-T2' && A == 0){ 

    MailApp.sendEmail({ 
    to: "[email protected]", 
    subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"", 
    htmlBody: "Dear ABC, "+ 


    "<p>Not Updated more than 30 Days = "+B+""+ 
    "<p>Not assigned to any one = "+C+""+ 

    "<P>&emsp;&emsp;&emsp;"+" "+ 

    "<p>Not updated more than 7 Days = "+D+" "+ 
    "<p>Not Updated more than 30 Days = "+E+""+ 
    "<p>Not assigned to any one = "+F+""+ 


    "<p>&emsp;&emsp;&emsp;"+" "+ 
    "<p>Best Regards,"+ 
    "<br>Global Service Desk "+, 
    cc: "[email protected]" 
         }); 


    } 
    else { 

    } 
    if(service == 'Global-Servicenow-Support-T2' && B == 0){ 
    MailApp.sendEmail({ 
    to: "[email protected]", 
    subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"", 
    htmlBody: "Dear ABC, "+ 

    "<p>Not updated more than 7 Days = "+A+" "+ 

    "<p>Not assigned to any one = "+C+""+ 

    "<P>&emsp;&emsp;&emsp;"+" "+ 

    "<p>Not updated more than 7 Days = "+D+" "+ 
    "<p>Not Updated more than 30 Days = "+E+""+ 
    "<p>Not assigned to any one = "+F+""+ 


    "<p>&emsp;&emsp;&emsp;"+" "+ 
    "<p>Best Regards,"+ 
    "<br>Global Service Desk "+, 

    cc: "[email protected]" 
    }); 


    } 



    else { 

    } 

當我通過if(service == 'Global-Servicenow-Support-T2' && A == 0)if(service == 'Global-Servicenow-Support-T2' && B == 0)傳遞條件它給了我單輸出或輸出正確的輸出。當我通過條件if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0)它給我輸出下面提到的所有3個條件。

if(service == 'Global-Servicenow-Support-T2' && A == 0)if(service == 'Global-Servicenow-Support-T2' && B == 0)if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0)

請幫我想單路輸出,當我通過條件if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0)

回答

0

變化情況

if(service == 'Global-Servicenow-Support-T2' && A == 0){ 

if(service == 'Global-Servicenow-Support-T2' && A == 0 && B != 0){ 

和變化情況

if(service == 'Global-Servicenow-Support-T2' && B == 0){ 

if(service == 'Global-Servicenow-Support-T2' && B == 0 && A != 0){ 

然後你將有一個輸出爲if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0)