Split Function Help
hi to all!
I have got this tables in Ninox:
TABLE: Genres
Field: Genre
TABLE: Masters
Field (in error): Genre
The field in TABLE Master can have 1 or more Genres, for example
(1 genre)
(2 genres)
With the formula:
Here is the formula field:
let xGenre := "";
if Genres = null then xGenre := "" else xGenre := Genres end;
let g := first(select Genres where Genre = xGenre);
html(---
<span style="color: black">Genre: </span>
<span onclick="ui.openRecord('{ g }')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">{ xGenre } <br></span>
---)
I am trying to have the possibility to link this field to the table called "Genres".
this correctly open the related record in the Table "Genres" only if the field in the table "Master" has one genre (first case), but do not work if genres are more than one.
I have tried to split the xGenres, but I have no chance.
Any help would be appreciated, as always
Thank you
37 replies
-
what kind of field is Genre in the Masters table?
-
let list := split(Genres, ", "); join(for i in range(0, cnt(list)) do "<span onclick=""ui.openRecord('" + first((select Genres)[Genre = item(list, i)]) + "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" + item(list, i) + "<br></span>" end, " ")
-
let x := split(Genres, ", ");
for item in x do
let i := first(select Genres where Genre = item);
html(---
<span onclick="ui.openRecord('{ i }')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">{ item } </span>
---)
endthis is working well:
every link is correctly related to the other table
The problem is when I want to add some lines inside the html space. if I do so they go into the cycle. if I put them outside the cycle, they lost the html formatting too e do not appear in the output
for example if I add this line:
<span style="color: black">Master Release: </span>
-
i am trying with this, but do not work:
let x := split(Genres, ", ");
let genrelines := for item in x do
let i := first(select Genres where Genre = item);
"<span onclick=""ui.openRecord('{ i }')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" +
item +
"<br></span>"
end;
html(---
<your other html code>{ genrelines }
<other code>
---) -
ui.popupRecord does not work for me. Did Ninox finally remove this feature?
are you using the MacOS app or the browser?
-
I managed to do in this way:
some codes
let injection := (
let x := split(Genres, ", ");
for item in x do
let i := first(select Genres where Genre = item);
html(---
<span onclick="ui.openRecord('{ i }')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">{ item }</span>
---)
end
);codes
<span style="color: black">Genre: </span>{ injection }<br>
codes
thanks Steven, thanks Fred
-
This code also works:
let list := split(Genres, ", "); let src := join(for i in range(0, cnt(list)) do "<span onclick=""ui.openRecord('" + raw(first((select Genres)[Genre = item(list, i)]).Id) + "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" + item(list, i) + "<br></span>" end, " "); html(src)
The problem was the ID of the target table. Putting it in a raw() function solved the problem.
-
said:
Yes works, but how can I do for include more fieldsGoing off of my example this is how my code changes:
let list := ( let x := split(Text, ","); for item in x do let i := first(select Table1 where Country = item); " <span style=""color: black"">Country: </span> <span onclick=""ui.openRecord('" + raw(i) + "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" + i.Country + "</span> <span style=""color: black"">Number: </span> <span onclick=""ui.openRecord('" + raw(i) + "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" + i.Number + "</span> " end ); html("" + list + "")
As you can see I drop the use of the for loop variable: item and just use the variable: i to get my information. Also I had to move the static text out of the html() command and into the for loop so it get created for each instance. Then you just duplicate the same bit of code for the first link then change the static name and the field references.
Content aside
- Status Answered
- 11 mths agoLast active
- 37Replies
- 388Views
-
5
Following