How to do some date validation here so that when user enter end date less than start date it will prompt error to user? Is there any built in function made by AppMaker? Thanks for sharing!
If you want to limit the input to a data model, you can use the Advanced section of the data model.
You can also achieve data validation through Event section or Data Validation section. Use the the first one to implement small scripts and the second one to hardcode rules into the app.
// date is not a previous date
var date = new Date();
if (widget.value < date) {
alert('Invalid date');
}
// date is not a future date
var date = new Date();
if (widget.value > date) {
alert('Invalid date');
}
// second date is not higher than first date
if (widget.value > widget.parent.descendants.firstDate.value) {
alert('Invalid date');
}
Related
I was trying to get the number of events that a specific user created in the past month using Google Calendar API.
The problem is that I got all the events where a user was invited. I don't see how to query only the events that user created.
calendarId: user's email adress
updatedMin : today - one month
I am using Google's api explorer to query Calendar API.
You can filter them by creator.email or organizer.email
Code:
function getCreatedEvents() {
var user = 'user#domain.com';
var today = new Date();
var date = new Date();
date.setMonth(date.getMonth() - 1);
var args = {
timeMin: new Date(date.getTime()).toISOString(),
timeMax: new Date(today.getTime()).toISOString()
}
var events = Calendar.Events.list(user, args).items;
events.forEach(function (event){
if(event.creator && event.creator.email == user){
// do something to events
Logger.log(event);
}
});
}
Output:
References:
DateTime
UpdatedMin Error1
UpdatedMin Error2
Calendar.Events.List
Include a query parameter in your request:
q: organizer==user#domain.com
This will filter to only events organized by user#domain.com.
Updated:
Unfortunately the query parameter does not accept key value pairs. This solution will not work.
event = "function main(){return Events({from_date: '2020-11-01', to_date: ... , event_selectors: [{event:'Search'}]}).groupByUser(['properties.Completion'], mixpanel.reducer.count())}"
What should I put after "to_date" to pull automatically pull today's date?
You can add a variable for today like in the following example:
function main() {
//Get today's date
var today = new Date ( (new Date())).toISOString().split('T')[0];
return Events({
from_date: '2020-11-01',
to_date: today,
})
.groupByUser(['properties.Completion'], mixpanel.reducer.count());
}
I have two Date customer components in XPages, One called startDate, another called EndDate. I have already got working validator method in Java for format validation. I want to do the Time range validation in Java code rather than xp:validateDateTimeRange.
Is it possible?When should be happened?It's in validation scope or later scope.
Thanks
To fit into the XPages & JSF validators and converters model, you would put your java code for format validation into a converter, and after doing the format validation, it should convert the submitted String to a java.util.Date. If the converter fails it should add a FacesMessage with the error message (there are blog posts with details - search FacesMessage).
[FYI, for date conversion there are many subtle gotchas around different date formats used in different countries, and around behavior when the browser and the server are in different timezones, and around handling daylight savings time in the different timezones.]
The converted Date object would then be made available to the validator (instead of the original string).
You can use a xp:validateExpression to call your Java date range validation. If you return false from the xp:validateExpression expression, it will use the error text provided in the message property. Else if you want to use different error messages use the FacesMessage mechanism instead of returning false.
Here's an example of a custom date date range converter:
<xp:validateExpression
message="The end date must be after the start date.">
<xp:this.expression><![CDATA[#{javascript:// Server-side validation.
// value is the end date java.util.Date object
var startDate = getComponent('inputText1').getValue();
if( null == startDate ){
// no start date - this error message not applicable, validation pass.
return true;
}
if( value.before(startDate) ){
// failed validation
return false;
}
return true;}]]></xp:this.expression>
<xp:this.clientScript><![CDATA[// client-side validation (browser JavaScript)
function validate(){
var startDate = dijit.byId('#{id:inputText1}').get('value');
var endDate = dijit.byId('#{id:inputText2}').get('value');
if( null == startDate || null == endDate){
return true; // this error message not applicable, passed.
}
if( endDate.getTime() < startDate.getTime() ){
return false; // failed validation
}
return true;
}
validate()
]]></xp:this.clientScript>
</xp:validateExpression>
</xp:this.validators>
I need to write a global javascript code that calculates age by birthday field and call the function from a diffrent javascript file to the specific entity.
from some reason i get error message "CalculateAge is undefined" after i loaded my entity javascript file to the form.
This is what i write in the global file:
CalculateAge: function (birthd)
{
if (birthd == null) {
return;}
var today = new Date().getFullYear();
year1 = birthd.getFullYear();
return (today-year1);
}
This is what i write in my entity file that i am loading to the form:
function onLoad() {
var birthDate = Xrm.Page.getAttribute("el_birth_date").getValue();
Xrm.Page.getAttribute("el_age").setValue(CalculateAge(birthDate));
}
I am new in Javascript.. Can ypu please help?
The JavaScript code you are using to calculate the age is not correct, it doesn't consider the month and the day.
A correct version is this one:
function CalculateAge(birthday, ondate) {
// if ondate is not specified consider today's date
if (ondate == null) { ondate = new Date(); }
// if the supplied date is before the birthday returns 0
if (ondate < birthday) { return 0; }
var age = ondate.getFullYear() - birthday.getFullYear();
if (birthday.getMonth() > ondate.getMonth() || (birthday.getMonth() == ondate.getMonth() && birthday.getDate() > ondate.getDate())) { age--; }
return age;
}
and can be used as:
var birthday = Xrm.Page.getAttribute("new_birthday").getValue();
var age = CalculateAge(birthday);
alert(age);
// age on 1st January 2000, JavaScript Date() object contains months starting from 0
var testdate = new Date(2000, 0, 1, 0, 0, 0);
var testage = CalculateAge(birthday,testdate);
alert(testage);
If you get CalculateAge is not defined, probably you didn't include the webresource containing your function inside the form. If you have two JS web resources (one containing the function, the other one containing the onLoad event) both need to be included inside the form.
If you are in a CRM version that has the issue of the asynchronous javascript loading, it's better to include the CalculateAge function in the same file as the onLoad event, but if you prefer keep them separate check this blog post: Asynchronous loading of JavaScript Web Resources after U12/POLARIS
The JavaScript function comes from my blog post: Calculate age in Microsoft Dynamics CRM 2011
I am tring to get a list of dates from my db that will eventually be used to populate a calendar. Each 'calendar event' has a start date & end date, i need to get all dates between & including the start & end date.
i am stuck on the WHERE statement, as i am not sure what to use for this
public List<EventFeed> GetCalendarDates()
{
return (from eventsList in GetEventsList()
select new EventFeed()
{
//EventDate = todo
}).ToList();
}
UPDATE
just to be clear, if i have a calendar event called foobar which starts on 22/08/2010 and ends on 24/08/2010, then i want my list return:
22/08/2010,
23/08/2010,
24/08/2010
thanks
kb
I had to do something similar recently, I used a Func<> to extract the dates from the range and used the result in the linq query.
I have added the same Func to your Linq query below. You didn't specify the name of the object that is returned by GetEventsList() so just replace the EventItem type for the first type parameter in the Func<> with whatever type you need.
public static List<EventFeed> GetCalendarDates()
{
Func<EventItem, List<DateTime>> extractEventDates = eventItem =>
{
var dates = new List<DateTime>();
for (var date = eventItem.StartDate;
date <= eventItem.EndDate;
date = date.AddDays(1))
{
dates.Add(date);
}
return dates;
};
return (from eventItem in GetEventsList()
from eventDate in extractEventDates(eventItem)
select new EventFeed
{
EventDate = eventDate
}).ToList();
}
You mean you want to select all the events that started on or after start date and ended on or before end date!
If yes, then this will help
var query = from #event in events
where #event.Start.Date >= startDate.Date
&& #event.End.Date <= endDate.Date
select #event;