- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 03:41 PM
Hello,
I'm trying to automatically set a due date field to whatever day is chosen but I want the time to ALWAYS be at 11:59 pm (last hour of due date). The code I'm using is placed on a task box inside a workflow. The result I'm getting is not what I'm looking for. Does anybody know if this code is the problem?
//current.comments = "Due date proposed: " + current.variables.due_date; var dateDueDate = due_date.toString()+ ' 23:59:59'; var dueDate = new GlideDateTime(dateDueDate); var dayOfWeek = parseInt(dueDate.getDayOfWeekLocalTime()); dueDate.setDisplayValue(dateDueDate, "yyyy-MM-dd HH:mm:ss"); dateString = "dd/mm/yyyy"; current.due_date = current.variables.due_date; var gdt = current.due_date.getGlideObject(); gdt.addDaysUTC(1);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 02:46 PM
this is the correct answer:
var dateDueDate = current.due_date;
var dueDate = new GlideDateTime(dateDueDate);
var arrDate = [];
arrDate = dueDate.toString().split(' ');
current.due_date.setDisplayValue(arrDate[0]+ ' 23:59:59','yyyy-MM-dd HH:mm:ss');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 09:09 AM
can you please just have this line and test,
current.variables.dueDate = current.variables.dueDate.toString().split(' ')[0]+ ' ' +'23:59:59';
are you trying to add 1 day in due date? if this is the case the i think, you can try in this way.
var dateDueDate = current.variables.dueDate;
var dueDate = new GlideDateTime(dateDueDate);
dueDate.addDaysUTC(1);
current.variables.dueDate = dueDate.setDisplayValue.split(' ')[0]+ ' ' +'23:59:59';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 10:04 AM
but where is the variable dueDate coming from? it doesn't exist in my form....
i tried this, but it didn't do the trick:
current.due_date = new GlideDateTime(current.due_date.toString().split(' ')[0]+ ' 23:59:59');
var gdt = current.due_date.getGlideObject();
gdt.addDaysUTC(1);
i think what you meant was:
var dateDueDate = current.due_date;
var dueDate = new GlideDateTime(dateDueDate);
due_date.addDaysUTC(1);
current.due_date = due_date.setDisplayValue.split(' ')[0]+ ' ' +'23:59:59';
and yes....I'm trying to add 1 day, and that part is actually working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 02:46 PM
this is the correct answer:
var dateDueDate = current.due_date;
var dueDate = new GlideDateTime(dateDueDate);
var arrDate = [];
arrDate = dueDate.toString().split(' ');
current.due_date.setDisplayValue(arrDate[0]+ ' 23:59:59','yyyy-MM-dd HH:mm:ss');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2020 06:20 PM
This worked fine!!!
In my case, original date field was in blank, and I needed to set it up with a new and fixed date.
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2020 05:46 AM
This will not work if the user has selected a different display format for dates in ServiceNow (which is uncommon, but could be around 5-10% of your userbase).
I'd recommend this:
var dueDate = new GlideDateTime(current.getValue("due_date"));
var dueDateMidnight = new GlideDateTime();
dueDateMidnight.setDisplayValueInternal(String(dueDate.getLocalDate()) + " 23:59:59");
current.setValue("due_date", dueDateMidnight.getValue());