- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 12:45 AM
Hi Guys,
I have a scenario where i need to add 5 business days to a date field. while adding 5 days it has to exclude the Saturday and Sunday.
Note: This is a date field. not a date and time.
Is there any solution?.. Please help me on this.
Thanks in advance.
Malaisamy J
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 09:49 PM
Hi Malaisamy,
Please replace the line var issueStartDate = current.issueStartDate.getGlideObject(); with below:
var issueStartDate = new GlideDateTime(current.issue_start);
Let me know, if this helps.
Regards,
Prajakta
PS - Please mark Helpful, Like, or Correct Answer if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 02:52 AM
Use the code i provided to add the days. And then check that if the result day is sat or sunday then add 1/2 days more
This will give you day of week
http://wiki.servicenow.com/?title=GlideDateTime#getDayOfWeek.28.29
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 03:44 AM
No..
The thing is issue start date is dynamic. Its not a constant field. So it may be any day of a week.
for example issue start date is "11-14-2016 09:00:00 AM" then my RCA due date should be "11-14-2016 09:00:00 AM"
In the same way if issue start date is "11-15-2016 09:00:00 AM" then my RCA due date should be "11-21-2016 09:00:00 AM"(Here Saturday and Sunday Excluded)
if issue start date is "11-16-2016 09:00:00 AM" then my RCA due date should be "11-22-2016 09:00:00 AM"
if issue start date is "11-17-2016 09:00:00 AM" then my RCA due date should be "11-23-2016 09:00:00 AM" and so on......
for this i need code. Can some one help me on this?..
Thanks,
Malaisamy J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 04:03 AM
Hi,
You can create a schedule or use existing if any, which runs on only weekdays. Use the schedule name in below code:
var issueStartDate = current.issueStartDate.getGlideObject();
var myScheduleName = 'Your schedule name'
var dueDays = 2; // no of days you want to add
var dueWorkingHours = 24; // specify the business hours of a day
// The amount of time we want for the duration
var dueSeconds = dueDays*dueWorkingHours*60*60;
var leadTime = new GlideDuration(dueSeconds*1000);
// Calculate the Due Date!
var dueDateGdt;
var sched;
var schedRec = new GlideRecord('cmn_schedule');
if (schedRec.get('name', myScheduleName)) {
if (typeof GlideSchedule != 'undefined'){
sched = new GlideSchedule(schedRec.sys_id);}
else{
sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);}
dueDateGdt = sched.add(issueStartDate , leadTime, '');
current.RCADueDate = dueDateGdt;
}
Let me know, if this helps.
Regards,
Prajakta
PS - Please mark Helpful, Like, or Correct Answer if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 07:51 PM
Hi Naik,
I have tried the above code.
but its is giving me error that "Glideobject() method is not applicable in scoped application".
When i changed this from
var issueStartDate = current.issueStartDate.getGlideObject();
to
var issueStartDate = current.issue_start.getDisplayValue();
i am getting below error.
So please help me to resolve this issue
Thanks
Malaisamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 09:49 PM
Hi Malaisamy,
Please replace the line var issueStartDate = current.issueStartDate.getGlideObject(); with below:
var issueStartDate = new GlideDateTime(current.issue_start);
Let me know, if this helps.
Regards,
Prajakta
PS - Please mark Helpful, Like, or Correct Answer if applicable.