Exécuter deux scripts en parallel sur une feuille sheets

Fermé
AxelF - 1 mars 2023 à 19:50
jordane45 Messages postés 38160 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2024 - 1 mars 2023 à 20:51

Bonjour,

Je suis très nouveau dans les scripts et j'ai deux scripts sur mon fichier qui fonctionnent très bien indépendement (soit l'un ou l'autre) mais j'aurai besoin que les deux scripts s'exécutent à même temps et en tout moment. Voici mes deux scripts en espérant que vous puissiez m'aider à les faire fonctionner simultanément.

Script 1:

/**
* Creates a Date Stamp if a column is edited.
*/

//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 2;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,4];
// Sheet you are working on
var SHEETNAME = 'Work'


function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}

Script 2

/**
* Creates a Date Stamp if a column is edited.
*/

//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 4;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,4];
// Sheet you are working on
var SHEETNAME = 'Work'


function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}

Comme vous voyez les deux se resemblent mais un c'est pour entrer la date du jour où une colone est modifié et l'autre pour entrer la date du jour où une autre colonne est modifié. Je vous confie mon fichier pour être plus clair.

https://docs.google.com/spreadsheets/d/1n3yOUo86zoArPVeecerl9Pfblq53gxTinfPAe6xIgRk/edit?usp=share_l...

A voir également:

1 réponse

jordane45 Messages postés 38160 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2024 4 657
1 mars 2023 à 20:51

Bonjour,

1 - A l'avenir, pour poster du code sur le forum, merci d'utiliser l'icone prévue à cet effet lorsque tu rédiges ton message

2  - Ta question concernant du javascript ... je la déplace dans le bon forum. merci d'y faire attention la prochaine fois

3 - Il suffit de fusionner tes deux codes

var COLUMNTOCHECK1 = 2;
var COLUMNTOCHECK2 = 4;

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  //checks that we're on the correct sheet.
  if( sheet.getSheetName() == SHEETNAME ) {
    var selectedCell = ss.getActiveCell();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    if( selectedCell.getColumn() == COLUMNTOCHECK1 ||  selectedCell.getColumn() == COLUMNTOCHECK2) {
      var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
      dateTimeCell.setValue(new Date());
    }
  }
}

0