3

Special syntax of the for loop

Hello to all,

this morning I discovered a new type of use of the for loop. My first exploration leads me to think that it is a possibility to enumerate a JSON structure (complex). The syntax is :
for id, [var of value] in [JSON] do

    // in this context, id is the key of the JSON and [var of value] contains the value of the key

end;

See this example to enumerate the content of the JSON variable config

var config := {
    sep: ",",
    qut: """",
    lf:"%0D%0A",
    numberFormat: "point",
    dateFormat: "locale",
    header: true,
    sepHeader: false,
    encoding: "utf8"
}

for id, value in config do
 id + " = " + value;
end;

return : 

sep = ,
qut = "
lf = %0D%0A
numberFormat = point
dateFormat = locale
header = true
sepHeader = false
encoding = utf8

I think there are many other possibilities, but I haven't found them yet. Maybe someone has another idea to use this type of for loop?

1 reply

null
    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    By adding some NativeJS (line 2) to convert a record to JSON, it is possible to retrieve all the fields of a record and its values : 

    var rec := (first(select Customer));
    var config := #{:any return rec}#
    for id, i in config do
     id + " = " + i;
    end;

    return :

    Created on = 
    Created by = 0
    Id = A1
    Modified on = 1667414018119
    Modified by = 7zBqhAKXxfQAPmH7Y
    First Name = Sofia
    Last Name = Young
    Companye = Kollwitz GmbH
    Postal Code = 12345
    City = New Jersey
    Address = 11,South Commerce Street
    Email = sofi@kollwitz-gmbh.com
    Customer No = K0001
    Title = 2
    Invoices = [1,16]
    Photo = shutterstock_307218608.jpg
    Category = 1
    Position = Marketing head
    FormuleA = 
    Formule = 
    Invoice total = 
    Print = 
    Print2 = 
    Sélection = 
    exViewEvent = []
    checked = true
    readed = true
    Bug nom de variable = 
    Formula = 
    Invoice = [1]
    Invoice2 = 
    Invoice3 = 
    ID = A1
    id = A1

Content aside

  • 3 Likes
  • 1 yr agoLast active
  • 1Replies
  • 167Views
  • 3 Following