Add Hours to a Date field on a WF Timer Script

jsummers
Kilo Contributor

Hello,

 

I'm using a Workflow Timer to wait for a date field but need to add hours to the Date, and can't seem to figure this one out. I'm referencing a variable (emp_start) that is a Date field on the RITM that the workflow is running on but it's not waiting for that date and proceeding through immediately. I'm wanting the workflow to continue at 9am on the emp_start date.

 

Here is what I've come up with so far, although fairly new to scripting, any help would be greatly appreciated:

 

var getDate = current.variables.emp_start;

var setDate = getDate.getGlideObject();

setDate.setHours(09);

setDate.setMinutes(00);

    var startDate = gs.dateDiff(gs.nowDateTime(), setDate, true);

        answer = startDate;

 

Thanks!

-Jon

1 ACCEPTED SOLUTION

Nope, the issue is the date format you're using, versus what my script is expecting.


Change this line:


var splitDate = getDate.split("-"); // Split Catalog Date into year, month, day  




To this line:


var splitDate = getDate.split("/"); // Split Catalog Date into year, month, day




Then change this line:


var startDate = new Date(splitDate[0],splitDate[1]-1,splitDate[2]);




To this line:


var startDate = new Date(splitDate[2],splitDate[0]-1,splitDate[1]);




Your date format on your instance is different than mine, hence the issue.


View solution in original post

16 REPLIES 16

swilson
Tera Expert

Hi, Jon. This script should do what you are after:



// Variable GlideDateTime


var getDate = current.variables.emp_start.getGlideObject();



// Convert to Javascript Date which has setHours and setMinutes functions


var d = new Date(getDate.getNumericValue());


d.setHours(9);


d.setMinutes(0);



// Convert Javascript Date to a GlideDateTime


var setDate = new GlideDateTime();


setDate.setValue(d.getTime());



// Set answer to seconds between now and our new date/time


answer = gs.dateDiff(gs.nowDateTime(), setDate, true);



Thanks.


- Steve


jsummers
Kilo Contributor

Steve,



Added it to the script of the timer of the workflow and this is the error I'm getting:


Fault Descript: getNumericValue is not a function


harikrish_v
Mega Guru

Or you can try this:-



var startDate = gs.dateDiff(gs.nowDateTime(), setDate.getDisplayValue(), true);


Harikrishnan,



Similar to Steve's, I'm getting the error after the workflow runs:


Fault Descript: getGlideObject is not a function