循环铅分配

Round Robin Lead Assignments

我正在尝试通过遍历 AE 列表并将“X”移动到下一个应分配的 AE 来将潜在客户分配给客户主管。我确定是否应将领导分配给某人的方法是公司名称旁边是否有空格。

基本上逻辑应该是,找到空白,找到 X 旁边的 AE 名称,使用该名称填充空白,找到下一个空白,依此类推,直到没有更多的空白。我已经写出了伪代码,但我根本不熟悉 Google App Scripts。谁能帮我弄清楚哪些代码适用于伪代码?

***
var STRINGX = 'X';
function main() {
  Logger.log(getNextPerson())
  var person = getNextPerson();
  var leadRow = findNextOpenLead();
  assignPersonToNextLead(person, leadRow);
  moveXDown();
}
function getNextPerson() {
  var sheet = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
  var startRow = 2;
  var salesReps = sheet[1].splice(0, 1)
}
function moveXDown() {
  // find column with x and save it as a variable
  // delete x from that column
  // add 1 to  column we found 
  // put it in ^ that column
}
function assignPersonToNextLead(person, leadRow) {
  // find row next to lead 
  // put person in the b column and row of lead
}
function findNextOpenLead() {
  // go through column b until you find an open cell
  // use that row in column d to find the lead 
}
***

A、B、C 代替了真实 AE 的名字

List of Account Executives names

Blanks next to Company names

对潜在客户列表进行循环分配

function roundRobinLeads() {
  const ss = SpreadsheetApp.getActive();
  const lsh = ss.getSheetByName('Round Robin Leads');
  const lvs = lsh.getRange(2, 1, lsh.getLastRow() - 1, lsh.getLastColumn()).getDisplayValues();
  const rsh = ss.getSheetByName('Round Robin');
  const rvs = rsh.getRange(2, 1, rsh.getLastRow() - 1, 2).getValues();
  let rr = { pA: [], index: 0, incr: function () { return this.index++ % this.pA.length; }, getIndex: function () { return this.index % this.pA.length; } };
  rvs.forEach((r, i) => {
    rr[r[1]] = r[0];
    rr.pA.push(r[1]);//push name in property array
    if (r[0]) {
      rr.index = i;//assign initial selection
      rsh.getRange(rr.index + 2, 1).setValue('');//remove x from current next
    }

  });
  lvs.forEach((r, i) => {if (!r[1]) {lsh.getRange(i + 2, 2).setValue(rr.pA[rr.incr()]);}});//assign lead and increment index
  rsh.getRange(rr.getIndex() + 2, 1).setValue('x');//record next assignment from rr.getIndex();
}

remainder %

我尝试添加其他内容,但 Stack Overflows 愚蠢的内容检查器将表格标记为格式不正确的代码。