Hi Team,
What expression or script can be used to set current date and time to a date attribute for the workflow extension built using thrust studio? Can the same expression be used for business workflows built using Core Content?
Thanks,
Dipali
If there are Accepted Answers, those will be shown by default. You can switch to 'All Replies' by selecting the tab below.
OK, so there are some utility functions that you can use, for your case, you can do this:
execution.setVariable("curDate", utils.now());
This will save the current date and time to a DATE variable so you can use it further. There are also other date functions in the utils namespace:
parseDate (takes a ISO date string and returns a DATE variable)
parseDateTime
Thanks .. this is really helpful.
Currently, the only way I know is to set it like this in a ScriptTask or in a listener of type Script:
execution.setVariable("curDate", new Date().toISOString());
However, it will save it as a string so when you will need to use it as date, make sure you cast it to a date:
const existingVar = execution.getVariable("curDate");
const d = new Date(existingVar);
Hope this helps.
Example, if you set the "curDate" variable somewhere in another task and you wanted to calculate the time difference to now, you would use the script in line 2 to set the variable curDate and then, when you want to calculate, you would do this in a ScriptTask or a Script event listener:
const d2 = new Date();
var diff = (d2- d)/1000;
execution.setVariable("diff", diff);