[英]How can I run 2 google.script.run if condition is met?
這是我正在嘗試做的事情:首先,如果 google 表格中的用戶狀態現在從活動狀態更改為非活動狀態,並且用戶仍處於登錄狀態,那么他將被注銷,以防他嘗試單擊其中的任何按鈕頁。 在這種情況下,例如刪除 (xBtn) 按鈕。
在 Js
//check user status
function logout_inactive_user(status){
if (status == "Inactive"){
logout();
return;
}
if (status == "Active"){
return false;
}
}
function retrieve_record(){
google.script.run.withSuccessHandler(display_row).testing_row_data();
}
//show user time log - home page
function display_row(tbl_arr){
//there are some code here to create table
var xBtn = document.createElement('button')
xBtn.onclick = function(){
google.script.run.withSuccessHandler(logout_inactive_user).check_user_status();
var task_id = number[4];
const response = confirm("This will delete task " + task_id + ". Proceed?");
if (response) {
google.script.run.deleteRows(task_id);
tbody.innerHTML = "";
retrieve_record();
}
}
}
在代碼 gs
var the_url = 'the spreadsheet url'; //sheet for code and list of usernames etc
var ss = SpreadsheetApp.openByUrl(url);
var ts = ss.getSheetByName("Sheet1");
var tHs = ss.getSheetByName("User_ID");
function doGet(e) {
const htmlOutput = HtmlService.createTemplateFromFile('Index');
return htmlOutput.evaluate();
}
function testing_row_data(){
//some code here
return variable
}
function check_user_status(){
//return user status
var status_data = tHs.getDataRange().getValues();
for(var i = 0; i<status_data.length;i++){
if(status_data[i][1] == userEmail){ //[1] because column B
var u_status = tHs.getRange(i+1,1).getValue() //user status column 1
}
}
return u_status;
}
function deleteRows(task_id) {
var rows = ts.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[4] == task_id) {
ts.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
雖然它不起作用。 而不是注銷用戶,它仍然允許用戶刪除行,即使他的狀態現在是不活動的。 沒有錯誤信息。
反正我已經想通了
function testing(){
google.script.run.withSuccessHandler(function(status){
var yes = "working";
//alert("checking if inactive");
if (status == "Inactive"){
alert("Oops! You no longer have permission to access this page. We will miss you!");
document.getElementsByTagName("body")[0].style.display = "none";
} else {
//alert("no");
google.script.run.alertTask(yes);
alert("starting task");
}
}).check_user_status();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.