How to add newDataValidation() code block into my Google apps script

twt333

So I have a block of code under the OnEdit(e) trigger. I have identified the range and it is working. The problem is I am now trying to add some data validation using apps script on that same range.

I have a block of code written out but I am unsure how to implement it properly on the desired range. I am currently using onOpen(e) and am also unsure if it is acting on the correct column as the data validation does not work when I run the code despite the REGEXMATCH expression being correct.

Any help would be greatly appreciated! Thanks.

Iamblichus

I am assuming that you want to change the background color and apply data validation only to the column B of a sheet called TermList. If that's the case:

  • The code that is creating the data validation is correct. As it is now, it should create a new data validation when you open the file. Actually, I would not include this in an onOpen trigger because you only need to create the data validation once, not every time you open the file.

  • In the following line you are comparing a Sheet to a string, something which can never return true. You should apply getName to the sheet. This might be the reason you think the data validation is not being properly inserted:

  if(sheet != 'TermList' && col != 2) return
  • You are also using offset(0, 0) for no reason (the range returned by this method is the one to which this method is applied, because you are not offsetting any row nor column).

  • If you want to change the background only if the sheet name is TermList and the edited column is B, then you should change this:

  if(sheet != 'TermList' && col != 2) return;
  var color = e.value;
  range.offset(0, 0).setBackground(color);

To this:

  if (sheet.getName() == 'TermList' && col == 2) {
    var color = e.value;
    range.setBackground(color);
  }

I hope this is of any help.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

내 Google Apps 스크립트에 newDataValidation () 코드 블록을 추가하는 방법

분류에서Dev

Post a tweet to my feed using Google Apps Script

분류에서Dev

Google-apps-script 함수 CHAR () 및 CODE ()

분류에서Dev

How can I tell my python script to wait for the "save as" dialogue box to pop out in chrome before executing the next block of the code?

분류에서Dev

How to render Google Pay button in Google Apps Script

분류에서Dev

How to get owners of libraries using Google Apps Script

분류에서Dev

How can I process a form using Google Apps Script?

분류에서Dev

How do I slice strings in Google Apps Script like in Python?

분류에서Dev

How to add legend with labels of IDs to my code

분류에서Dev

Google-apps-script SyntaxError

분류에서Dev

Google Apps Script 호출

분류에서Dev

How can I authorize Google Speech-to-text from Google Apps script?

분류에서Dev

How to block the use of apps from other users

분류에서Dev

Apps Script의 Google Docs API

분류에서Dev

Google 양식 + Apps Script onEdit

분류에서Dev

Google Spreedsheets Apps Script-On Cell Focus

분류에서Dev

Are there restrictions on using UrlFetchApp with Triggers in Google Apps Script

분류에서Dev

Google Apps Script 잘못된 값

분류에서Dev

Google Apps Script와 Firebase 통신

분류에서Dev

Add table to my dojo code

분류에서Dev

Google Apps Script를 통해 Chrome 탭 열기

분류에서Dev

Google Apps Script 용 V8 런타임

분류에서Dev

getSheets () Google Apps Script 다중 호출 문제

분류에서Dev

V8의 Google Apps Script 상속

분류에서Dev

Google Script Apps에서 셀 값 바꾸기

분류에서Dev

Google Apps Script의 첨부 파일 문제

분류에서Dev

여러 IF 조건이있는 Google Apps Script

분류에서Dev

Google Apps Script에서 배열 반환

분류에서Dev

Google Apps Script의 첨부 파일

Related 관련 기사

  1. 1

    내 Google Apps 스크립트에 newDataValidation () 코드 블록을 추가하는 방법

  2. 2

    Post a tweet to my feed using Google Apps Script

  3. 3

    Google-apps-script 함수 CHAR () 및 CODE ()

  4. 4

    How can I tell my python script to wait for the "save as" dialogue box to pop out in chrome before executing the next block of the code?

  5. 5

    How to render Google Pay button in Google Apps Script

  6. 6

    How to get owners of libraries using Google Apps Script

  7. 7

    How can I process a form using Google Apps Script?

  8. 8

    How do I slice strings in Google Apps Script like in Python?

  9. 9

    How to add legend with labels of IDs to my code

  10. 10

    Google-apps-script SyntaxError

  11. 11

    Google Apps Script 호출

  12. 12

    How can I authorize Google Speech-to-text from Google Apps script?

  13. 13

    How to block the use of apps from other users

  14. 14

    Apps Script의 Google Docs API

  15. 15

    Google 양식 + Apps Script onEdit

  16. 16

    Google Spreedsheets Apps Script-On Cell Focus

  17. 17

    Are there restrictions on using UrlFetchApp with Triggers in Google Apps Script

  18. 18

    Google Apps Script 잘못된 값

  19. 19

    Google Apps Script와 Firebase 통신

  20. 20

    Add table to my dojo code

  21. 21

    Google Apps Script를 통해 Chrome 탭 열기

  22. 22

    Google Apps Script 용 V8 런타임

  23. 23

    getSheets () Google Apps Script 다중 호출 문제

  24. 24

    V8의 Google Apps Script 상속

  25. 25

    Google Script Apps에서 셀 값 바꾸기

  26. 26

    Google Apps Script의 첨부 파일 문제

  27. 27

    여러 IF 조건이있는 Google Apps Script

  28. 28

    Google Apps Script에서 배열 반환

  29. 29

    Google Apps Script의 첨부 파일

뜨겁다태그

보관