Today's logic problem: I'm looking to dynamically generate an ncolumnta

Today's logic problem: I'm looking to dynamically generate an ncolumntable() for use in HTML documentation. For example, we collect task history in SQL and like to attach this in HTML emails and audit documents - each process may utilize a different set of history information, so I would like to build this table dynamically based on column header and field inputs, but can't seem to get the code working correctly. The idea is something like this:

load(
local!columns: {"Task","Owner"},
local!fields: {"task","owner"},
local!data: {{task: "Approval",owner: "Jim"},{task: "Submit",owner: "Steve"},{task: "Review",owner: "Joe"}},

ncolumntable(
local!columns,
apply(rule!test_getData(data: local!data, field: _),
local!fields
)
)
)

Where rule!test_getData() is defined simply as (data - Any Type, field - text):

index(ri!data,ri!field,null)

Since ncolumntable() is expecting a different array for each column, the...

OriginalPostID-195148

OriginalPostID-195148

  Discussion posts and replies are publicly visible

Parents
  • Chris, it seems that you cannot pass a dynamic number of parameters into this function since it expects the parameters to be comma separated arrays of strings and not lists of variant i.e. ncolumn(string[] column_headers, string[] column, string[] column2...) for up to ten columns.

    There are two workarounds I see possible
    1) Make your own expression rule to dynamically generate the HTML (a bit clunky at first but may scale better)
    2) Based off the length of the result of the apply function, create a set of if conditionals and pass the parameters using the index function, i.e.

    local!columnArray: apply(rule!test_getData(data:local!data,field_),local!fields),

    if( length(local!columnArray) = 1,
    ncolumn(local!columns,index(local!columnArray,1,{}),
    if(length(local!columnArray = 2),
    ncolumn(local!columns,index(local!columnArray,1,{}),index(local!columnArray,2,{})),
    ...
    etc.
Reply
  • Chris, it seems that you cannot pass a dynamic number of parameters into this function since it expects the parameters to be comma separated arrays of strings and not lists of variant i.e. ncolumn(string[] column_headers, string[] column, string[] column2...) for up to ten columns.

    There are two workarounds I see possible
    1) Make your own expression rule to dynamically generate the HTML (a bit clunky at first but may scale better)
    2) Based off the length of the result of the apply function, create a set of if conditionals and pass the parameters using the index function, i.e.

    local!columnArray: apply(rule!test_getData(data:local!data,field_),local!fields),

    if( length(local!columnArray) = 1,
    ncolumn(local!columns,index(local!columnArray,1,{}),
    if(length(local!columnArray = 2),
    ncolumn(local!columns,index(local!columnArray,1,{}),index(local!columnArray,2,{})),
    ...
    etc.
Children
No Data