- 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
08-11-2014 10:06 AM
Jon,
Does your variables line, in my script, look like:
var offboardDate = current.variables.emp_start.getDisplayValue();
Also, is it declared in the Variables (or Variables Set) as Type "Date"?
Finally, I'd add the following line to my script, then check your Workflow Context and let's see what is in the variable:
workflow.debug('Catalog date: ' + offboardDate);
Feel free to update the variable "offboardDate" to whatever makes sense in your script.
Can you post your current script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2014 10:14 AM
Jon,
I just decided to rewrite your script using my script...here's what I came up with (not tested):
// get date entered in catalog
var getDate = current.variables.emp_start.getDisplayValue();
var timeNow = new Date(); // Current Date/Time
var splitDate = getDate.split("-"); // Split Catalog Date into year, month, day
var startDate = new Date(splitDate[0],splitDate[1]-1,splitDate[2]); // Avoid timezone issues, but month starts at 0
startDate.setHours(9);
var dif = startDate.getTime() - timeNow; // Difference in milliseconds
var Seconds_from_T1_to_T2 = dif / 1000; // Convert to seconds
answer = Math.abs(Seconds_from_T1_to_T2); // Make sure it's not negative
workflow.debug('Catalog date: ' + getDate);
workflow.debug('Timer will end @: ' + startDate + ' ' +
(answer/60) + ' minutes from now' );
Let me know how that works for you.
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2014 10:20 AM
Thanks Rob.
Catalog date: 08/14/2014
Timer will end @: Invalid Date NaN minutes from now
Is there anything I should be setting for the 'Schedule based on' or 'Time zone based on' on the Timer?
- 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
08-11-2014 10:42 AM
Genius... that was it... thanks for sticking with me, Rob! Format will always be on the forefront of my mind from now on. Very much appreciated.
Thanks,
-Jon