How can return a value with a own function?ä
Hi,
I have created a own function and work fine, but for return value i have a problem, because my function dont return value.
Below my function.
Any help? Thanks
Robert
function htmlBarreHeures() do
let myReturn:= "";
for i from 1 to 48 step 1 do
let heureEnMinutes := 0;
heureEnMinutes := (i - 1) * 30 + 2;
let myHeure := "";
if i % 2 = 0 then
myHeure := text(" ")
else
myHeure := text(floor(i / 2))
end;
"";
"";
"De 00h00 à 05h00";
if heureEnMinutes > 0 and heureEnMinutes <= 300 then
myReturn := myReturn + "<span class=" + "'nuit'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
"";
"";
"De 05h00 à 12h00";
if heureEnMinutes > 300 and heureEnMinutes <= 720 then
myReturn := myReturn + "<span class=" + "'matin'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
"";
"";
"De 12h00 à 13h30";
if heureEnMinutes > 720 and heureEnMinutes <= 810 then
myReturn := myReturn + "<span class=" + "'midi'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
"";
"";
"De 13h30 à 18h00";
if heureEnMinutes > 810 and heureEnMinutes <= 1080 then
myReturnHtmlBarreHeures := myReturnHtmlBarreHeures + "<span class=" + "'apresmidi'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
"";
"";
"De 18h00 à 00h00";
if heureEnMinutes > 1080 and heureEnMinutes <= 1440 then
myReturn := myReturn + "<span class=" + "'soir'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
end;
myReturn;
end
13 replies
-
May I ask how you know it works fine? It looks like you are building an HTML string by concatenation, but you aren’t concatenating everything.
let myHeure := "";
if i % 2 = 0 then
myHeure := text(" ")
else
myHeure := text(floor(i / 2))
end;
""; Not concatenated
""; Not concatenated
"De 00h00 à 05h00"; Not concatenated -
I apologize! I just now took another look at your function, but this time it is on my computer and not my phone. I didn't realize those were comments until just now. I have a question. In this section...
"De 13h30 à 18h00";
if heureEnMinutes > 810 and heureEnMinutes <= 1080 then
myReturnHtmlBarreHeures := myReturnHtmlBarreHeures + "<span class=" + "'apresmidi'" + " style=" + "grid-column-start: " + heureEnMinutes + "; grid-column-end: span 30; >" + myHeure + "</span>" + "
"
end;
you have
myReturnHtmlBarreHeures
instead of justmyReturn
like you have in all of your other if statements. Is that intentional? If so, the variable hasn't been defined. Once, I changed that I was able to save the formula and it displayed the HTML. Did you define the function in Global script definitions or in a formula field. Did you call the functionhtmlBarreHeures()
after you defined it? I forgot to do that myself . I did call the function in the formula field after the function definition and it worked as expected. -
Hi Sean,
I thank you for your answer. With your answer I indirectly find my mistake. Indeed, I used to put ""; in my code to make it easier to read. And in my function I put two ""; after my return variable, suddenly my function returned empty hihihi. Many thanks. Indeed it is a function that I use to create a pure gantt diagram html and css for the representation of my appointments and interventions at my clients. When it's finished, if you want I can show you how it looks.
Have a nice day.PS: do you know how to sort a array on a specific element?
Robert
-
Hi Robert,
Yes, I would like to see it. I don’t have any experience with the new views at this point. Are you creating your own version?
I’m not sure what you mean by sorting an array by a specific element. Could you explain further.
PS: How did you know about the modulo operator? It’s not described in the documentation and I don’t think it was available some months back.
-
Hi Sean,
Thanks for your response, yes a i have create my hown gantt and i project to create a dashboard pure css and html for my custom crm.
For my gantt chart i want sort all my item by time. For this i use my table of all my apointements, but when i code:
let myAllApointment:= select('My Table of apointements')['date'=today()];
my variable (myAllApointment) it is not sorted and the first element in this array is id. Then for showing in my draw i want show my item by time sorted. For this i try to create a array with this tructure :
let myArray:=[myTimeValue, myDateValue,.....];
and after this i use built-in function sort like this
sort(myArray);
But i have many problem for creating a simple array and add element in this.
If you have info welcome
a little sample :
-
As far as I know, Ninox does not support multidimensional arrays. There isn't any documentation that shows it does and all of my attempts to define one have been unsucessful.
To put your selected records in order you should be able to use "order by". So, you would use select('My Table of apointements')['date'=today()] order by time, or "order by" plus your field name. If this works would you still need to use an array?
Your gantt chart looks nice!
-
And how i use 'order by' programatly?
-
Like this...
select('My Table of apointements')['date'=today()] order by time
-
select('My Table of apointements')['date'=today()]
i know, but after order by time???
-
i have never see this action in documentation
-
https://ninoxdb.de/en/manual/calculations/reference-of-functions-and-language
I’m not sure what you want to do, but here’s an example
For r in select('My Table of apointements')['date'=today()] order by time do
htmlValue := r.Field
end
You can iterate through the table to get the items you want to add to your web document
-
Hi,
Thanks very much. I never see befor the functionality for order but now sure i use this everywhere.
Best Regards
-
You're welcome. I haven't considered assigning a group of values using the select statement to a variable like you tried with...
let myAllApointment:= select('My Table of apointements')['date'=today()];
The first element was always Id because it was the only element since Ninox doesn't support multdimensional arrays. Another possibility is to use parallel arrays similar to this...
let myName := ((select Vendor)[text(State) = "TX"] order by Name).Name;
let myAddress := ((select Vendor)[text(State) = "TX"] order by Name).Address;
let myCity := ((select Vendor)[text(State) = "TX"] order by Name).City;
let myState := ((select Vendor)[text(State) = "TX"] order by Name).State;
item(myName, 8) + ", " + item(myAddress, 8) + ", " + item(myCity, 8) + ", " + item(myState, 8)
The last line gives this result - Premier Truck Group, 114 FM 881, Dallas, TX
Sean
Content aside
- 5 yrs agoLast active
- 13Replies
- 5615Views