- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 07:45 AM
Hi,
Would need help with converting a Date from any format of the user into the system format and then validate it for 3 business days from the present day.
We have tried a lot of thing but at one point it works and suddenly it stops working we tried ".getNumericValue()"
but that also doesn't seem to work for different formats we need it to be set to system format and only then it works very sporadically.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 02:21 AM
Okay so i was referring to this error and got an old community post which has helped us fix the issue. by using the script: var newString= String(oldString).valueOf();
So, this error comes because the value being returned is a Java string, and we are trying to process it as a javascript string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 02:21 AM
Okay so i was referring to this error and got an old community post which has helped us fix the issue. by using the script: var newString= String(oldString).valueOf();
So, this error comes because the value being returned is a Java string, and we are trying to process it as a javascript string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 02:30 AM
Nice to hear that, issue has been solved.
In that case you can mark this as closed.
Best Regards,
Pooja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 02:59 AM
Please share your latest scripts so that it helps community members in future.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 03:10 AM
Sure, Please check the script which i have used its the same as before just added the syntax from the solution provided which is marked as solution proposed.
var getplanneddatevalues = Class.create();
getplanneddatevalues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getValue: function() {
var userdateformat = gs.getUser().getDateFormat();
{
var time = new GlideDateTime().getTime().getDisplayValue();
var days = 3;
var prschedule = gs.getProperty('scheduled_24hrsX5');
var opened_st = new GlideDateTime();
var duration = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule(prschedule);
var duedate = schedule.add(opened_st, duration);
var gdt = new GlideDateTime(duedate);
var dateMil = gdt.getNumericValue();
var dateTi = this.getParameter('sysparm_date');
var dateTime = this.getParameter('sysparm_date').toString().split(' ');
var a1 = '/,-,.';
var a4 = a1.split(',');
var dateFor = String(gs.getUser().getDateFormat().toString()).valueOf(); // we have just added this into the script as per the original solution.
var j;
for (var i = 0; i < a4.length; i++) {
if (dateFor.contains(a4[i])) {
j = a4[i];
break;
}
}
var date = String(dateTime[0].toString()).valueOf();
var time1 = dateTime[1];
var rDate = {};
var dateCon = date.split(j);
var dateFor1 = dateFor.split(j);
for (var k = 0; k < dateFor1.length; k++) {
rDate[dateFor1[k]] = dateCon[k];
}
var rDateTime = rDate.yyyy + '-' + rDate.MM + '-' + rDate.dd + ' ' + time1;
var gdt1 = new GlideDateTime(rDateTime);
var startDateMil = gdt1.getNumericValue();
if (dateMil > startDateMil) {
return true;
} else {
return false;
}
}
},
type: 'getplanneddatevalues'
});
Thanks,
Saurabh Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 02:50 AM
check this and enhance
Variable Date no less than 5 business days
Auto-populating and validating date fields
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader