Problem using addHours for Date Time Field
Hi all,
I would like to calculate the "End Date & Time" field from the value in the "Date and Time" field. I am using expression as demonstrated in the expression examples on the SkyBow website (at least I think I am), but I keep getting the below error. What am I missing?
Failed eval expression: Error occurred on evaluating expression "{ return [[Date_x0020_and_x0020_Time]].addHours(1); }"TypeError: arguments[0].addHours is not a function
-
This error is usually due to the entity having no data.
I too have this problem and would love to know the answer since none of the examples in the Skybow documentation work.
When calling [[ColumnName]] it appears that the app assumes that the column already has data, but entering data into an empty field returns nothing like it doesn't see the data you have entered.
Skybow, please answer this issue as I need a solution too.0 -
The challenge to achieve the following result is to set the date and time in a valid localized format.
Use this Assignment expression:
[[Start_x0020_Time]].addHours(1).localeFormat("M/d/yyyy H:mm")
This is working for me in my English (en-us) site.
0 -
Hi Christof,
I am trying your suggestion but whenever I change Start Time I get an error and End Time doesn't change. Neither the date nor the time.
Any suggestions?
0 -
I did some research and can see that there is an issue with date values on sites it's local is not set to en-us:
then the datefield returns string instead of date object.
this is the result on en-us site (all is working):
and this from a en-gb (does not work since the returned type is a string instead a date object):
It's in our development now for fixing.
Btw, we have to handle empty inputs on date fields since an empty date field always returns a string not an object!
if (typeof [[Start_x0020_Time]] !== 'string') {
return [[Start_x0020_Time]].addHours(1).localeFormat("M/d/yyyy H:mm");
}
return null;0 -
Yes our site is set to en-gb so the time is set to European d/M/yyyy format as is most countries outside the US.
Is the a js function I can use in the meantime to resolve this?
0 -
Unfortunately we can not provide you a workaround for this problem at the moment.
We are working on a fix and publish it in a further release.
If you're experienced in scripting you can try to parse the result you get as string together with your regional settings into a valid date object, but it's definitely hard to accomplish and I think you have to include other libraries for dateformatting parsing.
We will keep you informed.
0 -
Hi Christof,
This has now become a high priority so I am looking into a work around and have come up with the following:
var eu_date = [[Start_x0020_Time]];
var parts = eu_date.split('/');
var us_date = parts[1] + '/' + parts[0] + '/' + parts[2];var endDate = new Date(us_date);
console.log('EU Date format: ' + eu_date);
console.log(parts);
console.log('US Date format: ' + us_date);return ('0'+endDate.getDate()).slice(-2)+'/'+('0'+(endDate.getMonth()+1)).slice(-2)+'/'+endDate.getFullYear()+' '+('0'+(endDate.getHours()+4)).slice(-2)+':'+('0'+(endDate.getMinutes())).slice(-2);
This works and I can change the Start Time and the End Time changes to the Start Time + 4 hours. Great!!!
HOWEVER....
Something strange is happening because as long as the day of the month is above 12 in Start Time all is well and End Time updates.But if I set the day in Start Time to 12 or below it throws the following error:
Failed value expressionError occured on evaluating expression "{ var meetingDateCalc = [[Start_x0020_Time]]; var dateString = meetingDateCalc.slice(0, -5); return [[Entity]] + " - " + [[Department]] + " Meeting " + dateString; }"
TypeError: meetingDateCalc.slice is not a function
Failed value expressionError occured on evaluating expression "{ var eu_date = [[Start_x0020_Time]]; var parts = eu_date.split('/'); var us_date = parts[1] + '/' + parts[0] + '/' + parts[2]; var endDate = new Date(us_date); //console.log('EU Date format: ' + eu_date); //console.log(parts); //console.log('US Date format: ' + us_date); return ('0'+endDate.getDate()).slice(-2)+'/'+('0'+(endDate.getMonth()+1)).slice(-2)+'/'+endDate.getFullYear()+' '+('0'+(endDate.getHours()+4)).slice(-2)+':'+('0'+(endDate.getMinutes())).slice(-2); }"
TypeError: eu_date.split is not a function
Very Important StatusFailed value expressionError occured on evaluating expression "{ var eu_date = [[Start_x0020_Time]]; var parts = eu_date.split('/'); var us_date = parts[1]+'/'+parts[0]+'/'+parts[2]; var endDate = new Date(us_date); var endYear = endDate.getFullYear(); var endMonth = (endDate.getMonth()+1); var endDay = endDate.getDate(); var endHours = (endDate.getHours()+4); var endMinutes = endDate.getMinutes(); console.log("EU Date format: "+ eu_date); console.log("US Date format: "+ us_date); return endDay + '/' + endMonth + '/' + endYear + ' ' + endHours + ':' + endMinutes; }"
TypeError: eu_date.split is not a functionDo you have any idea what's happening? It appears that the system tries to evaluate the date as US if the first number is 12 or below.
Best regards
Paul
0 -
Fix for this issue is released in newest Rich Forms version (3.1.27.7) and ready for download in Release Downloads SharePoint Add-Ins!
Use this Function Code expression in Calculated Value:
if (typeof [[Start_x0020_Time]] !== 'string') {
return [[Start_x0020_Time]].addHours(1);
}
return null;We have to handle empty inputs on date fields since an empty date field always returns a string not an object!0 -
This is great news, thank you Christof, I have already been in touch with Lightning Tools to their version (which I'm using) updated.
Thanks for getting this fixed. It has held our project up.
0
Please sign in to leave a comment.
Comments
9 comments