Skip to main content

Before starting this, I will say I have no background in writing script.  Any script/code I have posted was created using OpenAI API.

What I am trying to create is an automation that upon an update in a selected Single Select Field will begin an automation that utilizes a script to input today's date & time in an adjacent Time/Date field.

When I entered the code below into the Edit Script window and ran a test, the test failed with an error stating "

ReferenceError: document is not defined at main on line 12"
 
Can anyone provide feedback of what I need to change to make it work?
 

var today = new Date();

var options = {

  timeZone: 'America/New_York',

  hour: 'numeric',

  minute: 'numeric',

  second: 'numeric',

  hour12: true

};

var timeString = today.toLocaleString('en-US', options);

var dateString = today.toLocaleDateString('en-US');

var dateTimeString = dateString + ' ' + timeString;

var dateTime = document.createElement('div');

dateTime.innerHTML = dateTimeString;

document.body.appendChild(dateTime);

 

Found solution with @kuovonne's automation helpers.


Reply