Piyush Kathuria
Piyush Kathuria

Reputation: 11

Spreadsheet app script to check two conditions not working

I want to write a Spreadsheet Appscript to check for two conditions, namely Country and Status, and create a new sheet where these rows will be added. The code I've written is as follows :-

function Selection() {



var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getActiveRange().getValues();

var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Enter Country:', ui.ButtonSet.OK);
var country = response.getResponseText();

var arr = new Array;

for( var i in data )
  {
     if(data[i][7] == country)

    {
       if(data[i][28] = "Accepted")

        {
          arr.push(data[i])
        }

    }  

  }

var newsheet = sheet.insertSheet();

newsheet.setName("New");

New.getRange(2,1,arr.length,data[i].length).setValues(arr);

}

The code is not working for some reason. Any help will be appreciated.

Upvotes: 1

Views: 57

Answers (1)

Srikanth
Srikanth

Reputation: 836

if(data[i][28] = "Accepted")

should be

if(data[i][28] == "Accepted")

Upvotes: 1

Related Questions