A
A
Ayan Bai2021-01-10 07:19:50
Google Apps Script
Ayan Bai, 2021-01-10 07:19:50

How to call two functions in sequence?

Friends, good afternoon!

Lately my ID replacement function has started returning undefined. I don't understand why this is.

Plus, don't like this feature:

Функция в библиотеке которая меняет значения в ячейках Google таблицы
function tryChangeVID(f,r, db, table, col) {
  var sheet = db.getSheetByName(table);
  var range = sheet.getRange(col);
  var values = range.getValues();
  f = Number(f);
  r = Number(r);
  
  var res = f;
  
  for (var i = 0; i < values.length; i++) {
    if (values[i][0] === f) {
      values[i][0] = r;
      res = r;
    }
  }
  
  range.setValues(values);
  
  return res;
}

Мне нужно поменять ИД в двух таблицах. Коровы и их телята

exports.changeVID = function(find, repl, db){
  var result = tryChangeVID(find, repl,db,"Animals", "A:A");
  
  if(result === repl){
    result = tryChangeVID(find, repl, db, "Calves", "C:C");
  }
  
  return result;
}


The problem is that when the changeVID function is called, the replacement function for the second table (calves) does not work. That is, if(result === repl) is not true.

How can I correctly run these two functions in sequence, then return a new ID to the client as a result?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-01-10
@wolf47

The condition will not be fulfilled if in the first call, in the first table, there was no replacement.
Logic - as written, it is carried out. Mikhail correctly noted in the comment : removeif(result === repl)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question