The hours and Minutes should be set to 00:00 on date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 10:09 PM
We do have a "start_date" field available in the system, the requirement here is to set minutes and seconds to 00:00, similar to roundoff.
We have written a before update business rule, and to run when start_date changes. And below is the script written on the same.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var plannedStartDate = new GlideDateTime();
plannedStartDate.setDisplayValue(current.start_date.getDisplayValue());
gs.addInfoMessage("plannedStartDate:::"+plannedStartDate.getDisplayValue());
var time = plannedStartDate.getTime().getDisplayValue();
var date = plannedStartDate.getDate().getDisplayValue();
gs.addInfoMessage("time:::"+time);
var splittime = time.split(":");
var hours = splittime[0];
var minutes = splittime[1];
var seconds = splittime[2];
gs.addInfoMessage("hours:::"+hours+"::minutes:::"+minutes+"::seconds"+seconds);
var parsedPlannedStartDate = date+" "+hours+":00"+":00";
gs.addInfoMessage("parsedPlannedStartDate:::"+parsedPlannedStartDate);
current.start_date.setDisplayValue(parsedPlannedStartDate);
})(current, previous);
This business rule is working well as of now, but sometimes the getTime is returning the value which a variant to one hour. Like for example, if we have entered the time as "06-21-2017 12:34:12" --> It is setting it as "06-21-2017 11:00:00" .
So, can't we use getTime() in this scenario?
Or, Is there any other solution to achieve this? Any help is appreciated!!
Please help on this.
Regards,
Madhuri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 10:37 PM
Please try below code, i was also able to reproduce the issue but this worked fine in below way. Means the out of this "06-21-2017 12:34:12" will be "06-21-2017 12:00:00"
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var plannedStartDate = new GlideDateTime();
plannedStartDate.setDisplayValue(current.start_date);
gs.addInfoMessage("plannedStartDate:::"+plannedStartDate.getDisplayValue());
var dt = plannedStartDate.getDisplayValue().split(' ');
var time = dt[1];
var date = dt[0];
// var time = plannedStartDate.getTime().getDisplayValue();
// var date = plannedStartDate.getDate().getDisplayValue();
gs.addInfoMessage("time:::"+time);
gs.addInfoMessage("date:::"+date);
var splittime = time.split(":");
var hours = splittime[0];
var minutes = splittime[1];
var seconds = splittime[2];
gs.addInfoMessage("hours:::"+hours+"::minutes:::"+minutes+"::seconds"+seconds);
var parsedPlannedStartDate = date+" "+hours+":00"+":00";
gs.addInfoMessage("parsedPlannedStartDate:::"+parsedPlannedStartDate);
current.start_date.setDisplayValue(parsedPlannedStartDate);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 03:53 AM
Hi Shishir,
Thanks for your reply!
Could you please help with below questions
1) Is it the right way to set the time in business rules? or do we have any other feasible/optimized way to achieve this?
2) will it impact if the date and time format is different? will this work for all date and time formats?
3) will this value be stored in the database correctly?
Thanks,
Pavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 04:04 AM
Hi Shishir,
other observation!
if we try with your code, the hours value showing 2 hours less than the give hours
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 04:10 AM
Hi Shishir,
However, i tried by small change in your code as below. it looks working. But could you please help with below queries?
plannedStartDate.setDisplayValue(current.start_date); // Changed to plannedStartDate.setDisplayValue(current.start_date.getDisplayValue());
Could you please help with below questions
1) Is it the right way to set the time in business rules? or do we have any other feasible/optimized way to achieve this?
2) will it impact if the date and time format is different? will this work for all date and time formats?
3) will this value be stored in the database correctly?