- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2014 03:42 PM
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
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2014 10:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 10:58 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2014 12:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2014 01:34 AM
Or you can try this:-
var startDate = gs.dateDiff(gs.nowDateTime(), setDate.getDisplayValue(), true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2014 12:31 PM
Harikrishnan,
Similar to Steve's, I'm getting the error after the workflow runs:
Fault Descript: getGlideObject is not a function