Help

Some help with a (simple?) script for adjusting a time datefield in automation

Topic Labels: Automations
Solved
Jump to Solution
1379 5
cancel
Showing results for 
Search instead for 
Did you mean: 
mu71rd
6 - Interface Innovator
6 - Interface Innovator

Hi, I'm really new to scripting and despite a bit of ChatGPT help, I haven't got anything to work yet. I'm hoping that with a basic bit of help here that I can get going with my relatively limited coding knowledge...

I am doing a "when a record matches conditions..." trigger, and then hoping to find at records that have a start time of 00:00, update it to 09:00. this is because I'm hoping to drag/drop bookings onto a timeline and they default to 00:00 to 00:00 which doesn't work for our bookings system. 

I've found the field, and I can see in the record info, the {start} field shows (eg) 24-01-31T00:00:00.000Z.

I figured the easiest thing is to add 9 hours to that, so I'd started with this:

// Retrieve the start date-time from the input variables
let startDateTime = input.config().startDateTime; // 'startDateTime' matches the name given in step setup

// Check if startDateTime is provided
if (startDateTime) {
// Parse the start date-time string to a Date object
let startDate = new Date(startDateTime);

// Add 9 hours
startDate.setHours(startDate.getHours() + 9);

// Output the new date-time in ISO format
output.set('newStartDateTime', startDate.toISOString());
}

But this seems to not pick up any variables on the input.config().

Any help much appreciated

2 Solutions

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

I think you could do this without a script actually.  Just create a formula field with a DATEADD() that'll add 9 hours, then use that formula field's value for your "Update Record" action in your automation

See Solution in Thread

Just for your future attempts. It should work. Check your left side.

Alexey_Gusev_0-1706763548216.png

 

See Solution in Thread

5 Replies 5
TheTimeSavingCo
18 - Pluto
18 - Pluto

I think you could do this without a script actually.  Just create a formula field with a DATEADD() that'll add 9 hours, then use that formula field's value for your "Update Record" action in your automation

mu71rd
6 - Interface Innovator
6 - Interface Innovator

ah thank you so much! I had not thought to make a new field with the calculation in, and then use that field to trigger a simpler automation. I was trying to do some calculations within the automation itself, which of course didn't work. 

I will no doubt be back with script question, as they look so powerful, but this has done what I need now. Am so grateful to you. 🙏

Just for your future attempts. It should work. Check your left side.

Alexey_Gusev_0-1706763548216.png

 

Thank you that's kind - I'd actually not even noticed the left side! Noted now, and I have since got a different script to work, which is very exciting! 

I know that feeling. Sometimes one click to the 'almost obvious' thing blocks us from further development and costs many time and efforts to resolve 😀