0

Keep rID information in a JSON?

I have created a JSON object 

let t := this;
let xPart := unique(Results.Partners);
let xNewData := xPart.{
        Name: Horse.'Horse Name',
        rID: Horse.Id,
        Atm: switch t.League do
        case 2:
            sum(Results[Year_calc = t.year_calc and League = t.League and 'Round Type' = 1].attempted)
        default:
            sum(Results[Year_calc = t.year_calc and League = t.League].attempted)
        end,
}

There is much more, thus the reason for creating the JSON. Then I use the JSON data to create a HTML table.

I need to store rID information so I can use ui.popupRecord(). But of course JSON data is [any].

Is there a way to make this work?

11 replies

null
    • Sviluppatore Ninox
    • Fabio
    • 2 wk ago
    • Reported - view

    Hi Fred.

    Try passing the Horse.Id with raw() or string() which include the table reference. So ui.popupRecord() should work!

    Fabio

      • Fred
      • 2 wk ago
      • Reported - view

      Thanks for the tip. I tried raw and string but it didn't work. Ninox sees it as a string, but it needs it to be rID.

      • Sviluppatore Ninox
      • Fabio
      • 2 wk ago
      • Reported - view

      Hi .

      Assuming that from Table1 you want to open the first record of Table2, it should work with this code (JSON variant for your purposes):

      let firstRecord := first(select Table2);
      let xNewData := firstRecord.{
              rID: raw(Id)
          };
      "
      ";
      html(---
       <button onclick="ui.popupRecord('{ xNewData.rID }');">{ "POPUP RECORD" }</button>
      ---)

       

      Perhaps Ninext is installed in this database? If so, another parameter needs to be added. Take a look here: ui.popupRecord() and Ninext

      Fabio

      • Fred
      • 2 wk ago
      • Reported - view

      Thanks for bringing that up. I forgot about that Ninext changes how ui.popupRecord() works.

      So I tried:

      let xPart := unique(Results.Partners);
      let xNewData := xPart.{
              Name: Horse.'Horse Name',
              dID: raw(databaseId()),
              tID: tableId(Horse),
              rID: raw(Horse.Id),
      };
      code
      <tr onclick=ui.popupRecord('{ dID },{ rID }' )>
      code

      But nothing happens.

      • Ninox developper
      • Jacques_TUR
      • 2 wk ago
      • Reported - view

       I think the correct syntax would be :

      <tr onclick="ui.popupRecord('{ dID }','{ rID }')">
      • Fred
      • 2 wk ago
      • Reported - view

      sadly that didn't work either. Here is a bit more of the code:

      let tbleBody := xNewData.---
              <tr onclick="ui.popupRecord('{ dID }','{ rID }')">
                  <td>{ Name }</td>
                  <td></td>
                  <td></td>
              </tr>
          ---;
      
      • Ninox developper
      • Jacques_TUR
      • 2 wk ago
      • Reported - view

       Can you show me the result contained in tbleBody?

      • Fred
      • 2 wk ago
      • Reported - view

       

      Here is the code:

       

      let tbleHead := "
          <thead class='tableFixHead'>
              <tr>
                  <th>Name</td>
                  <th>" +
          if League = 2 then "R1Atm" else "Atm" end +
          "</th>
                      " +
          if League != 2 then "<th>AvP</th>" end +
          "
              </tr>
          </thead>";
      let tbleBody := xNewData.---
              <tbody>
              <tr onclick=ui.popupRecord('{ dID }','{ rID }')>
                  <td>{ Name }</td>
                  <td></td>
                  <td></td>
              </tr>
              </tbody>
          ---;
      html(---
      { css }<table>{ tbleHead }{ tbleBody }</table>
      ---)
      
      • Ninox developper
      • Jacques_TUR
      • 2 wk ago
      • Reported - view

       I asked you for the text content of tableBody, not the rendered output on the screen. It was to check if there were any syntax errors in the result and possibly test it in an HTML editor like VSCode or CodePen.

      • Fred
      • 2 wk ago
      • Reported - view

      sorry for the misunderstanding. Here is the JSON.

      [{"Name":"Contefina LVF","tID":"E","rID":979,"Atm":2,"Cl":1,"ROL":0,"JOAtm":0,"r1POAtm":0,"r3POAtm":0},
      {"Name":"A TOI DE PRIM","tID":"E","rID":1069,"Atm":1,"Cl":1,"ROL":0,"JOAtm":0,"r1POAtm":0,"r3POAtm":0}]
      
    • Fred
    • 2 wk ago
    • Reported - view

    Ok I got this to work:

    let tbleBody := xNewData.---
            <tr onclick=ui.popupRecord('{ dID }','{ rID }')>
            <td>{ Name }</td>
            <td></td>
            <td></td>
            </tr>
        ---;
    

    Why it didn't before I don't know. There was something else going wrong as it added space at the top of the table when it didn't before, but then I retyped everything between the three dashes and now it works.

    Thanks for helping me out.