Thanks everyone, esforim, item and eymen-elkum for the help on this. In digging further it seems that they built this into the product already. On a Task are 2 fields of interest; dateEnd and dateEndDate. They both map onto the same database field. The first one is of type date time, the second is of type date. If I assign to the 2nd one everything works well.
Thanks all.
Assigning a date to a date time field
Collapse
X
-
I do think that the solution that item referred to is the simplest and correct way to get today + 3 days as the default value.
BUT if I correctly understood, your problem is the type of the field, you need date and not datetime,
Okay, you have two action to take with to accomplish this:
go to the file: custom/Espo/Custom/Resources/metadata/entityDefs/Task.json
Update the "default" value manually from :
javascript: return this.dateTime.getDateTimeShiftedFromNow(3, 'days', 15);
TO
javascript: return this.dateTime.getDateShiftedFromToday(3, 'days');
Change the type from dateTime to date (this is optional)
Leave a comment:
-
Maybe something like this? Logically I think something like this.
dateEnd = datetime\hour(datetime\addDays(datetime\now(), 3),8)
Realistically, you probably end up with Error 500. Looking at the formula again, that formula was stupid of me;
Maybe this (might) work:
dateEnd = datetime\closest(datetime\addDays(datetime\now(), 3, 'time', '17:01')Last edited by esforim; 09-02-2020, 08:39 AM. -
I see your dilemma, but can't help you!
If that the case then you either need to do some sort of "All Day" conversation (I don't know how), or to make it a time pre-working hours (e.g. set it to be at 6am or 8am for example).
It convert the time to be 5:01pm (end of the day).
From all the formula I see, maybe if you somehow combine it with this: datetime\hour
It might work?
As for how, like I said first sentence, can't help you!Leave a comment:
-
Thanks, for the detail. I don't want to hide the time part of the field, I just want the time portion to be unassigned. When using the user interface I can specify a date then optionally a time. The time segment can be left empty. This works in certain ways when sorting that I want.
In script I currently have
Code:dateEnd = datetime\addDays(datetime\now(), 3);
I want the script equivalent of setting the time section of that field to be empty within the user interface.
Thanks
Leave a comment:
-
Ah I read your post again, it seem like you want to hide the "Time" section? I don't think you can do that through GUI, why not just create a "Date" field instead?
To answer your question about formula, I did a test of it and it seem to work fine.
As an experiment, I created two field, one is a Date-Time field call datedue. You don't have to make two.
one is a Date field call datedue2
Then I create this formula for my Task
datedue=datetime\addDays(dateEndDate, 3);
datedue2=datetime\addDays(dateEnd, 2)
Let break it down.
datedue = field name
datetime\addDays() = formula
dateEndDate or dateEnd = default field available for Task, dateEnd is Date-Time field, dateEndDate is a Date field (All-day mode).
3 or 2 = How many days I want to add, I want add 3 and 2, I can also do -1 (yesterday) if I want to.
) = close off the formula
; = to allow for new formula to be written
Please see all the formula here: https://docs.espocrm.com/administrat...mula/#datetime
and See https://docs.espocrm.com/administration/formula/#datetimeadddays
I also use this variation too: datedue=datetime\addDays(dateEnd, 1)Last edited by esforim; 09-02-2020, 08:24 AM.Leave a comment:
-
Hello,
you can create un custom folder entityDefs .. a task.json with somethink like this : so dateDue go from type dateTime to date
PHP Code:{
"fields": {
"dateDue": {
"notNull": false,
"type": "date",
"default": null,
"after": null,
"before": null,
"isCustom": true
}
}
Leave a comment:
-
Thanks for the suggestion, I really need the ability to do it in script though because the +3 varies depending on many other things.Leave a comment:
-
Assigning a date to a date time field
Hi, your advice would be appreciated here.
On my tasks I have a "Date Due" field which is of type date time (I believe this is the default configuration).
In script I want to assign the Date Due of now plus 3 days. I want the result to just be the date without the time.
How do I do this? It sounds simple but I cannot work it out.
ThanksTags: None
Leave a comment: