简体   繁体   English

脚本编辑器中的多个条件问题

[英]Issue with multiple conditions in script editor

I've created a script editor for a google sheet that has multiple tabs.我为具有多个标签的谷歌工作表创建了一个脚本编辑器。 One if statement I can't seem to get working is - If sheet "Employee Evolution" column 8 EQUALS "Disqualified" AND column 13 is NOT EQUAL to "NO DATA", move the row to sheet "Disqualified" I've tried so many different ways to rearrange and can't get it to work.我似乎无法正常工作的一个 if 语句是 -如果工作表“员工进化”第 8 列等于“不合格”且第 13 列不等于“无数据”,则将该行移至“不合格”表我试过了许多不同的方式来重新安排,但不能让它发挥作用。

 **function onEdit(event) {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var s = event.source.getActiveSheet();
      var r = event.source.getActiveRange();
      if(s.getName() == "Employee Evolution" && r.getColumn() == 8 && r.getValue() == "Disqualified" && r.offset.getValue(0,5) != "NO DATA") {
        var row = r.getRow();
        var numColumns = s.getLastColumn();
        var targetSheet = ss.getSheetByName("Disqualified");
        var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
        s.getRange(row, 1, 1,numColumns).moveTo(target);
    s.deleteRow(row);** 

I have no coding experience, so I'm having a difficult time understanding javascript documents that explain this stuff.我没有编码经验,所以我很难理解解释这些东西的 javascript 文档。 Please help!请帮忙!

Below is the link to my spreadsheet https://docs.google.com/spreadsheets/d/1vp46hMbmB5968cRW2BGhS66qqNhl91Llk8xeknlRuQc/edit#gid=0下面是我的电子表格https://docs.google.com/spreadsheets/d/1vp46hMbmB5968cRW2BGhS66qqNhl91Llk8xeknlRuQc/edit#gid=0的链接

Right now I only have the first if statement and else if statement set up with multiple conditions, but that is not working.现在我只有第一个 if 语句和 else if 语句设置了多个条件,但这不起作用。 When I populate the 8th column (H) with Disqualified and populate the 13th column (M) with anything at all, nothing happens.当我用 Disqualified 填充第 8 列 (H) 并用任何东西填充第 13 列 (M) 时,什么都没有发生。 And, if I populate column H with Qualified and populate column M with Paid Search, nothing happens.而且,如果我使用 Qualified 填充列 H 并使用付费搜索填充列 M,则不会发生任何事情。

Basically I want the row to move to either the PPC tab or the Disqualified tab.基本上我希望该行移动到 PPC 选项卡或 Disqualified 选项卡。 However, I don't want the row to move until both columns H and M are populated with specific text.但是,在 H 和 M 列都填充了特定文本之前,我不希望该行移动。 If column H says "Qualified" AND column M says "Paid Search" the row should move to the PPC tab.如果 H 列显示“合格”且 M 列显示“付费搜索”,则该行应移至 PPC 选项卡。 If column H says "Disqualified" AND column M says anything other than NO DATA (even Paid Search), the row should move to the Disqualified tab.如果 H 列显示“不合格”且 M 列显示除 NO DATA(甚至付费搜索)以外的任何内容,则该行应移至“不合格”选项卡。

The problem I can't get past is that I need to have each if statement look at both columns before executing true.我无法解决的问题是我需要让每个 if 语句在执行 true 之前查看两列。

I hope this makes sense and thank you for your help.我希望这是有道理的,并感谢您的帮助。

It's not possible to define if that if should be working or not based just on the code as we don't have that spreadsheet you're using.由于我们没有您正在使用的电子表格,因此无法仅根据代码来定义是否应该工作。

But I do notice some things that maybe are wrong on yout assumptiong, for this break that if into:但是我确实注意到一些可能在您的假设上是错误的事情,因为这打破了,如果进入:

  • s.getName() == "Employee Evolution" => Checks if the current sheet that you have active is called "Employee Evolution" s.getName() == "Employee Evolution" => 检查您激活的当前工作表是否称为“Employee Evolution”
  • r.getColumn() == 8 => checks if the current column that you have active is column number 8 (column h) r.getColumn() == 8 => 检查您当前活动的列是否为第 8 列(第 h 列)
  • r.getValue() == "Disqualified" => checks if the current cell that you have active is equal to Disqualified (must matcha case as well) r.getValue() == "Disqualified" => 检查您当前活动的单元格是否等于 Disqualified(也必须匹配大小写)
  • r.offset.getValue(0,5) != "NO DATA") => Checks if column offset by 5 (will be equal column 13 indeed) is different then "NO DATA" (also must match case) r.offset.getValue(0,5) != "NO DATA") => 检查列偏移量 5(实际上等于第 13 列)是否不同于“NO DATA”(也必须匹配大小写)

And of course as this function is onEdit, so this code will only run when you change something on the spreadsheet.当然,因为这个 function 是 onEdit,所以这个代码只会在您更改电子表格上的某些内容时运行。

So I suppose by reading that code is that whenever someone changes column 8 to "Disqualified" (must match the capital letters as well) and all the other criterias match, it should be moved to "Disqualified" sheet.所以我想通过阅读该代码,每当有人将第 8 列更改为“不合格”(也必须匹配大写字母)并且所有其他标准都匹配时,它应该被移至“不合格”表。 Pay attention to all the case sensitive scenarios you have.请注意您拥有的所有区分大小写的场景。

I think overall the code seems fine.我认为总体而言,代码看起来不错。 Share the spreadsheet so we can check what might be going wrong.共享电子表格,以便我们检查可能出现的问题。

PS: by something being active I mean that your cursor is clicked/selected that thing PS:通过某些活动,我的意思是您的 cursor 被单击/选择了那个东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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