Is there a way to convert cell values to integer using apps script and display its difference in specific column? I have this sheet database that contains fields in the picture, 1 and using apps script, I wanted to compute columns M and N automatically using apps script. Column M (Remaining Qty) should be the difference between balance_qty column and issue_qty column if balance_qty is greater than restock_point otherwise, column M (Remaining Qty) would be the difference between balance_qty and restock_point. For the column N (Replenish Qty) it should be the difference between issue_qty and balance_qty if balance_qty is less than the issue_qty. I tried to make a script below:
function calc() {
var ss = SpreadsheetApp.getActive();
var range = ss.getSheetByName("Database").getRange("datas").getValues();
for(var x = 0; x < range.length ; x ++){
var balance = range[x][7];
var issue = range[x][4];
var receipt = range[x][12];
var pr = range[x][13]
var rPoint = range[x][8];
if(balance < 0){
pr.setValues(balance.toString());
receipt.setValues(0)
}else if(balance < issue){
var diff = issue - balance;
var rec = balance - rPoint
pr.setValues(diff.toString());
receipt.setValues(rec.toString());
}else{
var rem = balance - issue;
receipt.setValues(rem.toString());
}
}
}
but it still missing something.
Note: That the range "data" is cell from A4:N19