Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
I am trying to get the Date () function to work in my Run Code action to no avail. Is this an issue with the JS environment inside of Flow?
Code:
const now = new Date();
console.log(now);
Output:
1970-01-04T00:00:00.000Z
Expected Output:
2024-07-06T02:23:45.506Z
Solved! Go to the solution
This is an accepted solution.
Thank you for your response. After reading the Run Code Action Limitations, found here, I realized JS date and time functions do not work entirely in Run Code.
I accomplished what I needed to by including the order creation time in the input and used that as my timestamp. Then I was able to calculate what I needed from there.
Input:
query{
order{
tags,
createdAt
}}
Code:
export default function main(input) {
const creationTime = input.order.createdAt;
Hi @craiganderson ,
What environment are you running? You can use the code below to check the environment's timezone.
const now = new Date();
// Time as an ISO string
console.log("Time ISO " + now.toISOString());
// timezone offset
console.log("Timezone Offset: " + now.getTimezoneOffset());
// time in the local timezone
console.log("LocalTime: " + now.toLocaleString());
==================================================
Result:
Time ISO: 2024-07-06T03:52:20.911Z
Timezone Offset: -420
Local Time: 7/6/2024, 10:52:20 AM
If it's helpful with you, please give me a like and mark it as a solution.
Thanks in advance.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution.
MIDA: Heatmap, Record & Replay |BLOOP Referral Program, Reward |
Need help from our expert? Kindly share your request with us via [email protected]
This is an accepted solution.
Thank you for your response. After reading the Run Code Action Limitations, found here, I realized JS date and time functions do not work entirely in Run Code.
I accomplished what I needed to by including the order creation time in the input and used that as my timestamp. Then I was able to calculate what I needed from there.
Input:
query{
order{
tags,
createdAt
}}
Code:
export default function main(input) {
const creationTime = input.order.createdAt;
Out of curiosity, did you find a workaround for this? I'd been aware of those limitations but hadn't run across a use case that was blocked by them until seeing this.
This is the intended way to solve it. Unfortunately random dates are a security risk.
Nice had a feeling that would be the way to do it. Can't really think of a case where generating arbitrary time stamps that aren't linked to dates tied to objects would be necessary.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024