Setting current date and time in a Flow

Mahesh_Krishnan
Giga Guru

OK.  I know this should be real simple but not getting the code to work.

I am setting a date field using a script instead of a data pill in one of the steps in a flow using the following code:

var invite_dt = gs.nowDateTime();

return invite_dt;

The system keeps resetting the above code to just GlideDateTime. 

I have spent an hour figuring this seemingly simple task out and now reaching out to the experts here.

Thanks in advance!

Mahesh

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

If you're just wanting to set a field in flow to be the current time, GlideDateTime will work

find_real_file.png

You can even reference the community live stream

View solution in original post

8 REPLIES 8

Kieran Anson
Kilo Patron

Hi,

It should be new GlideDateTime(); as your function rather than using the glide system method.

var invite_dt = new GlideDateTime();

return invite_dt.getDisplayValue();

Anish Reghu
Kilo Sage
Kilo Sage
var gr = new GlideRecord('table_name'); 
gr.invite_dt = gs.nowDateTime();

 

You need not return here, unless you are calling a function. You did miss a GlideRecord into the table where your field (date field) lies. That's all. You create a object for the table and using the object, you store the value fetched via nowDateTime() GlideSystem method into your date field.

Try the solution from Kieran as well and let us know what went well in this case. I would be happy to correct myself in my learnings, if this is wrong. 

 

Mark as Correct Answer if this response helped you solve your query, and mark it helpful as well. 

Mahesh_Krishnan
Giga Guru

Anish:

When I tried your code I got an error stating that the code needs to return a value.

Kieran:

The GlideDateTime() class manipulates existing dates; it does not set the current system date.

I was not able to get the flow to even accept the code.  Not sure if I am doing something wrong here.

I realize the mistake I did. Thanks for notifying.