workflow - Adding second approver in expense Approval report -
i wanted add second approval in expense report approval. have taken script this tutorial.
the condition able check state (1) if approved send email second approval, able put manager_email in state2 field. failing change state2 either "approved" or "denied" can trigger email director_email in state3 final approval stage.
function onreportorapprovalsubmit(row) { // procurement approvals spreadsheet var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheets()[0]; var lastrow = sheet.getlastrow(); // set status of new request 'new'. // column o status column sheet.getrange(lastrow,getcolindexbyname("status")).setvalue("new"); // initialize open procurement request (responses) spreadsheet editing // active spreadhseet since script stored it. var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheets()[0]; // initialize approval spreadsheet editing // open procurement approvals var approvalsspreadsheet = spreadsheetapp.openbyid(approvals_spreadsheet_id); var approvalssheet = approvalsspreadsheet.getsheets()[0]; // open second procurement approvals var approval2sspreadsheet = spreadsheetapp.openbyid(approvals2_spreadsheet_id); var approval2ssheet = approval2sspreadsheet.getsheets()[0]; // open third procurement approvals var approval3sspreadsheet = spreadsheetapp.openbyid(approvals3_spreadsheet_id); var approval3ssheet = approval3sspreadsheet.getsheets()[0]; // fetch data procurement request spreadsheet var data = getrowsdata(sheet); // fetch data first approvals spreadsheet // getrowsdata creates searchable 2d array var approvalsdata = getrowsdata(approvalssheet); // fetch data second approvals spreadsheet var approval2sdata = getrowsdata(approval2ssheet); // fetch data third approvals spreadsheet var approval3sdata = getrowsdata(approval3ssheet); // every procurement request // iterate through 2d array of procurement request (responses) sheet data (var = 0; < data.length; ++i) { var row = data[i]; row.rownumber = + 2; // if state field empty newly submitted request if (!row.state) { // new request // email supervisor request / approval sendreporttosupervisor(row); sheet.getrange(row.rownumber, column_state).setvalue(row.state); } else if (row.state == state_supervisor_email) { // if request has been sent supervisor iterate through // check if supervisor has accepted or rejected request in approval spreadsheet (var j = 0; j < approvalsdata.length; ++j) { var approval = approvalsdata[j]; // if current request not same last request id number // don't stop if (row.rownumber != approval.procurementrequestid) { continue; } // send approval results requestor notifying supervisor's decision sendapprovalresults(row, approval); // put supervisor's email in state field mark being sent supervisor approval sheet.getrange(row.rownumber, column_state).setvalue(row.state); // send approval request manager if (row.state == "approved"){ sendreporttomanager(row); sheet.getrange(row.rownumber, column_state2).setvalue(row.state2); // put supervisor's email in state field mark being sent supervisor approval } else if (row.state2 == state_manager_email) { // update state of report approved or denied sheet.getrange(row.rownumber, column_state2).setvalue(row.state2); if (row.state2 == "approved"){ // send final approval request director sendreporttodirector(row); sheet.getrange(row.rownumber, column_state3).setvalue(row.state3); // put director's email in state field mark being sent supervisor approval } else if (row.state3 == state_director_email) { // update state of report approved or denied sheet.getrange(row.rownumber, column_state3).setvalue(row.state3); // stop if request id number , current request id same. means there // no new requests check break; } } }
Comments
Post a Comment