I need some help with a Script Node. I am trying to create a script node that can give TWO variables to use in a string of the current Date/Time and another Date/Time in the past “X” amount of hours given by a previous entity called “LogOveride” The Date/Time format of both needs to be like this: “2022-02-24T09:00:00”
So far I have this to start but its not working:
var today = new Date();
var date = today.getFullYear()+"-"+(today.getMonth()+1)+"-""today.getDate();
var time = today.getHours()+"-"+today.getMinutes()+"-"+today.getSeconds();
var datetime = date+"T"+time;
I’m not sure how to have it create the set for the “X” hours previously and set the two variables to be used in a follow on “Service” Node. I assume the service node will look like this:
Every script node runs in its own sandbox, so if you want data to be available in subsequent nodes then you must store it in the context object.
I would also recommend looking into the Moment library, which is imported by default and available through a koreUtil object. It would provide much nicer date and time formatting options.
Thank you Andy, I am very new to this so can you help me as to what my “Script” node would look like and the line for my “Display” node: Here is what I am getting from the Documentation.
//Script Node
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
context.USdate=koreUtil.intl.DateTimeFormat('en-US').format(date);
//Display Node
{{context.nameofscriptnode.USdate}}
Also at this point not sure how to use the koreUtil.moment to use the entities variable for hours to make a second date/time back that many hours from the now date.
All of those will generate strings that are stored in different variables in context. Then you can reference them in another node as simply context.date1 etc. You do not include the original script block name in the reference.