简体   繁体   中英

If statement placement for user input(google apps script with code.gs, page.html, page-css.html,page-js.html)

I am creating a web app that allows the user to select their current department , which department they will be temporarily loaned to, the task they are doing, and the time spent on the task. I need to write some sort of statement that will determine the team they are on (current or new) based on the selection of their current department.

I have tried multiple placements of the "if statement" in various places

//// code for appending new row into sheet need to add "team" as the second ////variable    
function userClicked(userInfo){
    ws.appendRow([user,userInfo.department,userInfo.tempDepartment,userInfo.task,userInfo.timeSpent,new Date()]);
}

//// function for selecting the varibales that get appended into worksheet
function doStuff() {
    var userInfo = {};

    userInfo.department = document.getElementById('department').value;
    userInfo.tempDepartment = document.getElementById('tempDepartment').value;
    userInfo.task = document.getElementById('task').value;
    userInfo.timeSpent = document.getElementById('timeSpent').value;

    google.script.run.userClicked(userInfo);

    document.getElementById('timeSpent').value='';
    var dpt = document.getElementById('department');
    dpt.selectedIndex=0;
    M.FormSelect.init(dpt);
    var tempDpt = document.getElementById('tempDepartment');
    tempDpt.selectedIndex=0;
    M.FormSelect.init(tempDpt);
    var task = document.getElementById('task');
    task.selectedIndex=0;
    M.FormSelect.init(task);

I'm going out on a limb trying to answer such a confusing question, but here's my attempt.

Add a team property to the userInfo object, fill it in with an if statement, and add it to the sheet when appending.

function userClicked(userInfo){
    ws.appendRow([user,userInfo.department,userInfo.tempDepartment,userInfo.team,userInfo.task,userInfo.timeSpent,new Date()]);
}

//// function for selecting the varibales that get appended into worksheet
function doStuff() {
    var userInfo = {};

    userInfo.department = document.getElementById('department').value;
    userInfo.tempDepartment = document.getElementById('tempDepartment').value;
    userInfo.task = document.getElementById('task').value;
    userInfo.timeSpent = document.getElementById('timeSpent').value;
    if (userInfo.department == "Refill") {
        userInfo.team = "New";
    } else {
        userInfo.team = "Old";
    }

    google.script.run.userClicked(userInfo);
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM