0

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

null
    • Fred
    • 1 yr ago
    • Reported - view

    what kind of field is Genre in the Masters table?

      • francescostefanello
      • 1 yr ago
      • Reported - view

       the field is text field 

      • Fred
      • 1 yr ago
      • Reported - view

      wow so you manually type in the genres? may I ask why you don't make it a dynamic multiple choice field?

      • francescostefanello
      • 1 yr ago
      • Reported - view

       i am sorry I misunderstood, this field is filled form the RYM site, through a Python request

       

      • Fred
      • 1 yr ago
      • Reported - view

      you didn't misunderstand me. It is just my feeble mind that couldn't figure out that there are smarter ways of getting data. 😉

    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view
    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, "
    ")
      • francescostefanello
      • 1 yr ago
      • Reported - view

       I get this output:

       

      <span onclick="ui.openRecord('3')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">Blues Rock<br></span> <span onclick="ui.openRecord('')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">Psychedelic Rock<br></span> <span onclick="ui.openRecord('2')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">Acid Rock<br></span>

      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

      Is this is not what you want? Don't you need 1 or 2 or 3 or ... clickable lines in your html output? You can adapt the code to get them all in one line i guess. I think you'll have to put the join line in a variable and put it in the html...

      • francescostefanello
      • 1 yr ago
      • Reported - view

       

      this is the output

    • francescostefanello
    • 1 yr ago
    • Reported - view

    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

    this 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>

      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

       what about this? First generate the html code lines outside the html and then inject it with your other html code...

      let list := split(Genres, ", ");
      let genrelines := 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, "
      ");
      html(---
      <your other html code>
      {genrelines}
      <other code>
      ---)
      
      • francescostefanello
      • 1 yr ago
      • Reported - view

       your code is great but I can not open the related records with it...

       

      could you continue your example with mine:

      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

       

      that open correctly the records

       

      T H A N K  Y O U  A  L O T

      • francescostefanello
      • 1 yr ago
      • Reported - view

       

       

      nothing happens if I click on them

    • francescostefanello
    • 1 yr ago
    • Reported - view

    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>
    ---)

    • Fred
    • 1 yr ago
    • Reported - view

    ui.popupRecord does not work for me. Did Ninox finally remove this feature?

    are you using the MacOS app or the browser?

      • francescostefanello
      • 1 yr ago
      • Reported - view

       i am using the browser and it works fine for me but the error is somewhere in the formula...

      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

       I don't think Ninox will remove this because their new template "Leave Planner" is also using this. It is a very educational template.

    • francescostefanello
    • 1 yr ago
    • Reported - view

    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

    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    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.

      • Fred
      • 1 yr ago
      • Reported - view

      I have this:

      let list := split(Text, ", ");
      let content := join(for i in range(0, cnt(list)) do
              "<span onclick=""ui.openRecord('" +
              raw(first((select Table1)[Country = item(list, i)]).Id) +
              "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" +
              item(list, i) +
              "<br></span>"
          end, "
      ");
      html(content)
      

      The links show up but when I click on the link it takes me to the root table list page.

      I have attached the DB. It doesn't work in the MacOS app or the browser. If you look in Table2, you will see at the bottom of the record form, Formula 6.

      • francescostefanello
      • 1 yr ago
      • Reported - view

       

       

      this works fine for you

       

      let list := (
              let x := split(Text, ",");
              for item in x do
                  let i := first(select Table1 where Country = item);
                  html(---
          <span onclick="ui.openRecord('{ i }')"; style="color: #1E90FF; cursor: pointer; text-decoration: underline;">{ item }</span>
                  ---)
              end
          );
      html(---
      <span style="color: black">Country: </span>{ list }<br>
      ---)

      tested and working

      • francescostefanello
      • 1 yr ago
      • Reported - view

       

      copy and paste it manually, don't use the copy command on the right

      • Fred
      • 1 yr ago
      • Reported - view

      Thanks. It is interesting that your code uses html() twice. I would think you would only use it once, but it works.

      Playing around I was able to remove the html() from the loop and added the raw() command that recommended and it now works:

      let list := (
              let x := split(Text, ",");
              for item in x do
                  let i := first(select Table1 where Country = item);
                  "
          <span onclick=""ui.openRecord('" +
                  raw(i) +
                  "')""; style=""color: #1E90FF; cursor: pointer; text-decoration: underline;"">" +
                  item +
                  "</span>
                  "
              end
          );
      html("
      <span style=""color: black"">Country: </span>" +
      list +
      "<br>")
      
      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Fred Hi Fred.

      Yes works, but how can I do for include more fields 

      Example Title: Track: etc

    • Fred
    • 1 yr ago
    • Reported - view
     said:
    Yes works, but how can I do for include more fields 

    Going 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
  • 1 yr agoLast active
  • 37Replies
  • 425Views
  • 5 Following