- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2016 12:27 PM
While I would finally call myself mediocre at scripting, i am still very much amateur at date scripting.
I am setting up a workflow where I want an if script to run. I want the if script to say:
if ((current date + 4 days) > current.variables.req_start_date){
return 'yes';
}
return 'no';
}
Basically, return true if the current date is 4 days or less away from the start date.
I don't really know how to put this into javascript the correct way or if i need to parse the current date out, if the start date on the form needs to be coming from a date field or if it can be a string field.... I'm assuming it has to be a date field.
Also, if anyone has a better way to accomplish this, I am totally open.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2016 01:45 PM
Alex have the script like:
answer = ifScript();
function ifScript()
{
var date = new GlideDateTime(current.variables.req_start_date);
var currentDate = new GlideDateTime();
if((date.getNumericValue() - currentDate.getNumericValue()) > (4 * 24 * 60 * 60 * 1000) )
{
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2016 01:45 PM
Alex have the script like:
answer = ifScript();
function ifScript()
{
var date = new GlideDateTime(current.variables.req_start_date);
var currentDate = new GlideDateTime();
if((date.getNumericValue() - currentDate.getNumericValue()) > (4 * 24 * 60 * 60 * 1000) )
{
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 08:37 AM
Well, I have only put it through a couple tests but it seems to be working splendidly! Thank you!!!
Out of curiosity, would the script stay the same if req_start_date was a date field rather than a string??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 08:39 AM
If 'req_start_date' is Date Time field then it will work.
If its date field then you need to do something like:
var date = new GlideDateTime(current.variables.req_start_date + ' 01:00:00' );

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2016 10:55 AM
So Mani I am trying to do the same type of thing. My scenario is the start date can not be BEFORE the Open date of the request.
Would I use the same script and then I want to include an Alert message to tell the customer something like: "Please select a date after today's date." Or something to that effect is that right.
Thanks,
Karen