Sort and display all times in order.
Hello everyone! In my table, I’ve set up two time fields (as shown in the image). I’m wondering if I can create a code snippet in the ‘View’ table to display all the entries of time1 and time2 in sequential order. I tried some code, but it wasn’t successful. Thanks for your help!
let getCopy := (select 'table');
let pailie := for xx in getCopy do
let times := [];
if xx.'time1' != null then
times := times + [xx.'time1']
end;
if xx.'time2' != null then
times := times + [xx.'time2']
end;
let sortedTimes := sort(times);
let formattedTimes := for time in sortedTimes do
format(time, "YYYY-MM-DD")
end;
formattedTimes
end;
3 replies
-
There is no time data in time2.
Do you mean you want to sort Date then Time?
-
Hi
There are a couple of issues here:
- you are creating an array of dates and trying to add these view element which is not possible - view elements are designed to display records which can then be linked through from the view.
- I have discovered that the array needs to be initialised with a type in order for the addition of elements to work - so let times := [text(void)].
I have created the following code which will display these dates in a formula field (with each on a separate line):
let getTimeRecs := (select Table);
let times := [text(void)];
for timeRec in getTimeRecs do
if timeRec.'Time 1' != null then
times := array(times, [format(timeRec.'Time 1', "YYYY-MM-DD")])
end;
if timeRec.'Time 2' != null then
times := array(times, [format(timeRec.'Time 2', "YYYY-MM-DD")])
end
end;
let sortedTimes := sort(times);
join(sortedTimes, "
")Not sure if this will help you or not but feel free to come back.
Content aside
- 11 hrs agoLast active
- 3Replies
- 27Views
-
3
Following