I have a data sheet, containing: |ItemCode | Item | Version|
The goal is to get the last version of the item and increment it by 0.1, so if the item's version is 03, then its new version would be 3.1 once this function was called.
The code below finds the first, but not the last occurrence in range(data sheet). I need to find the last version for that item and increment it:
function newVersion() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("ArquivoItens");
var range = sheet.getRange(2,1,ss.getLastRow(),3).getValues();
var editarSheet = ss.getSheetByName('EditarItem');
var itemCode = editarSheet.getRange("W5").getValue();
var version = editarSheet.getRange("AC4").getValue();
for(var a = 0; a < range.length; a++){
if(range[a].lastIndexOf(itemCode)>-1){
Logger.log("Código: "+ itemCode);
Logger.log("Versão: "+ range[a][2]);
Logger.log("Produto: "+ range[a][1]);
Logger.log(range[a].indexOf(itemCode));
return range[a][2];
}
}
Any light is appreciated.