I successfully connected to Google sheet and the script does what it suppose to do but the issue is that when I put job.log() function in the script but Switch skips them. Check the code below
Code: Select all
async function jobArrived(s,flowElement,job){
checkGs("Product Name",job);
}
async function checkGs(productName,job){
const {google} = require('googleapis');
const spreadsheetId = 'xxxxxxxxx00000xxxxxxx';
const client = new google.auth.JWT(
"test@xxx.iam.gserviceaccount.com",
null,
"-----BEGIN PRIVATE KEY-----\\n-----END PRIVATE KEY-----\n",
['https://www.googleapis.com/auth/spreadsheets'],
);
const Sheets = google.sheets({version:'v4' , auth:client});
//Get all Rows
Sheets.spreadsheets.values.get({
spreadsheetId: spreadsheetId,
range: "test!A:B"
}, (err, result) => {
if (err) {
console.log(err);
} else {
job.log(LogLevel.Warning, 'I am here 1 '); //<< Switch skips this and doesn't run it
source = result.data.values;
const input = source.map(function (row, index) {
row.unshift(index);
return row;
}).filter(function (iRow) {
return iRow[1] === productName;
});
var index = parseInt(input[0]) + 1;
input[0].shift();
if (input[0][1] < 1) {
job.log(LogLevel.Warning, 'Not available in the inventory')//<< Switch skips this and doesn't run it
}else{
input[0][1] = input[0][1] - 1;
let values = [
input[0]
];
const resource = {
values
};
Sheets.spreadsheets.values.update({
spreadsheetId: spreadsheetId,
range: "test!A" + index + ":B" + index,
valueInputOption: "RAW",
resource : resource
}, (err, result) => {
if (err) {
console.log(err);
} else {
job.log(LogLevel.Warning, 'Found in inventory')//<< Switch skips this and doesn't run it
}
})
};
}
});
}
By the way the function that connects to Google sheet and do the checkup is being executed but it skips the job.log() functions
Any idea for the solution?