OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Creating TimeStamp using APPS SCRIPT, when B column was changed [duplicate]

  • Thread starter Thread starter Kiwi juice
  • Start date Start date
K

Kiwi juice

Guest
I have already code in apps script and would like to add Timestamp function in the same google sheet, using Apps Script.

Whenever users encode B column, Timestamp in A column should be encoded Automatically by Appls Script.

I will show my current code in the file, as below. Let me know how and which code I should add.

Thank you in advance.

Code:
const WEBHOOK_URL = 'I encoded here my Slack channel webhook url'; 

function sendSlackNotification(sheetName, cell, value) {
  var message = `Sheet: ${sheetName}\n Cell: ${cell}\n New Value: ${value}\n==========================`;

  Logger.log(message);

  var payload = {
    text: message
  };

  var options = {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(payload)
  };

  UrlFetchApp.fetch(WEBHOOK_URL, options);
}

function onChange(e) {
  var sheet = e.source.getActiveSheet();
  var sheetName = sheet.getName();

   var lastRow = sheet.getLastRow();
  var lastColumn = sheet.getLastColumn();
  var range = sheet.getRange(lastRow, 1, 1, lastColumn);
  var cell = range.getA1Notation();

  var value = range.getValues()[0]; 

  sendSlackNotification(sheetName, cell, value);
}

<p>I have already code in apps script and would like to add Timestamp function in the same google sheet, using Apps Script.</p>
<p>Whenever users encode B column,
Timestamp in A column should be encoded Automatically by Appls Script.</p>
<p>I will show my current code in the file, as below.
Let me know how and which code I should add.</p>
<p>Thank you in advance.</p>
<pre><code>const WEBHOOK_URL = 'I encoded here my Slack channel webhook url';

function sendSlackNotification(sheetName, cell, value) {
var message = `Sheet: ${sheetName}\n Cell: ${cell}\n New Value: ${value}\n==========================`;

Logger.log(message);

var payload = {
text: message
};

var options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload)
};

UrlFetchApp.fetch(WEBHOOK_URL, options);
}

function onChange(e) {
var sheet = e.source.getActiveSheet();
var sheetName = sheet.getName();

var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(lastRow, 1, 1, lastColumn);
var cell = range.getA1Notation();

var value = range.getValues()[0];

sendSlackNotification(sheetName, cell, value);
}
</code></pre>
 
Top