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-27-2017 10:46 PM
Hi Pavan,
Great it helped you.
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?
I think BR is right 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?
You are just trying to make the time (mm:ss) as 00:00, then shouldn't be any issue as i think the time format will always be same irrespective what the date format is.
3) will this value be stored in the database correctly?
Yes, it saves the value but then you are trying before update business rule in that case it will set the start_date every time if updates happens. I would suggest change the BR to After Insert.
Please provide your feedback if it helps.