mardi 3 avril 2018

Google Script to define variables in If statement in a loop

I'm new to Google Script. And I'd like to create a function that checks if the content has been filled up correctly. If some columns don't contain the specific words or they contain nothing while the value of column L is "Y", then it should show an alert message accordingly. If everything is good, then show the message "Campaign info's been added correctly!"

Here's the script that I wrote:

function Validation() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());

for (var i = 0;i < range.length; i++) {
var campaign_live = range.getCell(i, 12).getValue();
var test_type = range.getCell(i, 6).getValue();
if (campaign_live == "Y" && test_type != "Subject" && test_type!= "Sender"){
Browser.msgBox("Wrong Test Type in Column G, please check.", Browser.Buttons.OK_CANCEL);
} 
var Template = range.getCell(i, 8).getValue();
if (campaign_live == "Y" && Template != "HTML" && Template!= "TEXT"){
Browser.msgBox("Wrong Template in Column H, please check.", Browser.Buttons.OK_CANCEL);
} 
var Sender = range.getCell(i, 9).getValue();
if (campaign_live == "Y" && Sender == "" ) {
Browser.msgBox("Missing Sender in Column I, please check.", Browser.Buttons.OK_CANCEL);
} 
var Subject = range.getCell(i, 10).getValue();
if (campaign_live == "Y" && Subject == "" ) {
Browser.msgBox("Missing Subject in Column J, please check.", Browser.Buttons.OK_CANCEL);
} 
var Content = range.getCell(i, 11).getValue();
if (campaign_live == "Y" && Content == "" ) {
Browser.msgBox("Missing Content in Column K, please check.", Browser.Buttons.OK_CANCEL);
}  
}
Browser.msgBox("Campaign info's been added correctly!");

}

The script can be executed, however, no matter what content I have in the cells that I have indicated in the loop, it only shows the message "Campaign info's been added correctly!". It seems to me the loop part is totally ignored in the process.

Do you have any idea why it doesn't work? Thanks a lot in advance for your kind response.

Best regards, Daisy

Aucun commentaire:

Enregistrer un commentaire