在费用审批报告中添加第二个审批者

时间:2015-05-11 17:57:54

标签: workflow

我想在费用报告批准中添加第二个批准。我从this tutorial获取了剧本。

条件是能够检查状态(1)如果批准然后发送电子邮件到第二批准,它也能够将MANAGER_EMAIL放在state2字段中。但它没有将state2改为" APPROVED"或者" DENIED"这样它就可以在state3中触发DIRECTOR_EMAIL的另一封电子邮件,这是最后的审批阶段。

function onReportOrApprovalSubmit(row) {


    // This is the Procurement Approvals Spreadsheet
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheets()[0];
      var lastRow = sheet.getLastRow();

      // Set the status of the new request to 'New'.
      // Column O is the Status column
      sheet.getRange(lastRow,getColIndexByName("Status")).setValue("New");

      // Initialize open Procurement Request (Responses) spreadsheet for editing
      // This is the active spreadhseet since this script is stored with it.
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheets()[0];

      // Initialize Approval spreadsheet for editing
      // Also open the  Procurement Approvals
      var approvalsSpreadsheet = SpreadsheetApp.openById(APPROVALS_SPREADSHEET_ID);
      var approvalsSheet = approvalsSpreadsheet.getSheets()[0];

        // Open the Second Procurement Approvals
     var approval2sSpreadsheet = SpreadsheetApp.openById(APPROVALS2_SPREADSHEET_ID);
     var approval2sSheet = approval2sSpreadsheet.getSheets()[0];

      // Open the Third Procurement Approvals
     var approval3sSpreadsheet = SpreadsheetApp.openById(APPROVALS3_SPREADSHEET_ID);
     var approval3sSheet = approval3sSpreadsheet.getSheets()[0];

      // Fetch all the data from the Procurement Request Spreadsheet
     var data = getRowsData(sheet);

      // Fetch all the data from First Approvals spreadsheet
      // GetRowsData creates a searchable 2D array 
      var approvalsData = getRowsData(approvalsSheet);

       // Fetch all the data from Second Approvals spreadsheet
      var approval2sData = getRowsData(approval2sSheet);

       // Fetch all the data from Third Approvals spreadsheet
       var approval3sData = getRowsData(approval3sSheet);

      // For every procurement request
      // Iterate through 2D array of Procurement Request (Responses) sheet data
      for (var i = 0; i < data.length; ++i) {
       var row = data[i];
        row.rowNumber = i + 2; 

        // If State field is empty then this a newly submitted request
        if (!row.state) {
         // This is a new request
          // Email the Supervisor to Request his / her Approval

          sendReportToSupervisor(row);
           sheet.getRange(row.rowNumber, COLUMN_STATE).setValue(row.state);
               } else if (row.state == STATE_SUPERVISOR_EMAIL) {

          // If the request has already been sent to the Supervisor then iterate through
          // Check if the Supervisor has accepted or rejected the request in the Approval spreadsheet

          for (var j = 0; j < approvalsData.length; ++j) {
          var approval = approvalsData[j]; 

            // If current request is not the same as the last request id number
            // Then don't stop
            if (row.rowNumber != approval.procurementRequestId) {
              continue;
            }

            // Send approval results to requestor notifying Supervisor's decision
            sendApprovalResults(row, approval);

          // Put Supervisor's email in state field to mark it as being sent to Supervisor for approval
          sheet.getRange(row.rowNumber, COLUMN_STATE).setValue(row.state);

    // Send Approval Request to Manager
      if (row.state == "APPROVED"){

    sendReportToManager(row);
           sheet.getRange(row.rowNumber, COLUMN_STATE2).setValue(row.state2);
         // Put Supervisor's email in state field to mark it as being sent to Supervisor for approval
               } else if (row.state2 == STATE_MANAGER_EMAIL) {

             // Update the state of the report to APPROVED or DENIED
           sheet.getRange(row.rowNumber, COLUMN_STATE2).setValue(row.state2);

      if (row.state2 == "APPROVED"){
         // Send final Approval Request to Director

        sendReportToDirector(row);
           sheet.getRange(row.rowNumber, COLUMN_STATE3).setValue(row.state3);

         // Put Director's email in state field to mark it as being sent to Supervisor for approval
               } else if (row.state3 == STATE_DIRECTOR_EMAIL) {

             // Update the state of the report to APPROVED or DENIED
           sheet.getRange(row.rowNumber, COLUMN_STATE3).setValue(row.state3);

            // Stop if the request id number and current request id are the same. This means there
            // are no new requests to check
          break;
         }
        } 
       }

0 个答案:

没有答案