Title: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Sean H. on August 10, 2022, 12:06:29 pm I was wondering if there is a simpler way to get Multidimensional Arrays to work with Form Screen Arrays for Displays/Inputs
I have a Global Multidimensional Array set up like this tier01 dynamic array of record t01_id integer, t01_code varchar(10), tier02 dynamic array of record t02_id integer, t02_code varchar(10) end record end record Which is just holding Dummy Data for Testing like this let tier01[1].t01_id = 1 let tier01[1].t01_code = "T1-1" let tier01[1].tier02[1].t02_id = 1 let tier01[1].tier02[1].t02_code = "T1-1 T2-1" let tier01[1].tier02[2].t02_id = 2 let tier01[1].tier02[2].t02_code = "T1-1 T2-2" let tier01[2].t01_id = 2 let tier01[2].t01_code = "T1-2" let tier01[2].tier02[1].t02_id = 3 let tier01[2].tier02[1].t02_code = "T1-2 T2-3" let tier01[2].tier02[2].t02_id = 4 let tier01[2].tier02[2].t02_code = "T1-2 T2-4" let tier01[2].tier02[3].t02_id = 5 let tier01[2].tier02[3].t02_code = "T1-2 T2-5" let tier01[3].t01_id = 3 let tier01[3].t01_code = "T1-3" let tier01[3].tier02[1].t02_id = 6 let tier01[3].tier02[1].t02_code = "T1-3 T2-6" And am wanting to display it to a very basic Form layout(windowStyle="standard") vbox group(text="Tier 01") table(height=1 lines) { [t01a ][t01b ] } end end group(text="Tier 02") table(height=1 lines) { [t02a ][t02b ] } end end end end attributes edit t01a = formonly.t01_id, title=%"ID"; edit t01b = formonly.t01_code, title=%"Code"; edit t02a = formonly.t02_id, title=%"ID"; edit t02b = formonly.t02_code, title=%"Code"; instructions delimiters " " screen record screen_tier01(t01_id, t01_code) screen record screen_tier02(t02_id, t02_code) end The Phantom Fields don't seem to work for Array Fields so I had to create duplicate Global Flat Arrays to get the display working # work around for displaying only tier01_flat dynamic array of record t01_id integer, t01_code varchar(10) end record, # work around for displaying only tier02_flat dynamic array of record t02_id integer, t02_code varchar(10) end record Then I can use the Display Array as normal dialog d_display_tier01() display array tier01_flat to screen_tier01.* end display end dialog dialog d_display_tier02() display array tier02_flat to screen_tier02.* end display end dialog Then I am just copying the data from the Multidimensional Array into each respective Flat Array so it can be applied to the displays. I'm just wondering if there is a better way to do this that doesn't need the creation of the Flat Arrays so I can stick with a single Multidimensional Array. Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Reuben B. on August 12, 2022, 07:57:54 am A comment on your code under Display Array as normal. With two flat arrays, you can use multi-dialog.
So something like this, uses the before row of the tier01 flat array to change what is in the tier02 flat array and the user can click freely between the two arrays. Code
Otherwise for complex arrays that are readonly there is always the web component path, see https://github.com/FourjsGenero/wc_2darray Your idea of using phantom field "The Phantom Fields don't seem to work for Array Fields" is nice but doomed as arrays are done by position. See this example http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_DisplayArray_030.html and discussion http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Migrate_to_300_struct_arr.html Reuben Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Reuben B. on August 15, 2022, 02:26:00 am I was thinking afterwards I could improve that code ...
The copy in the BEFORE ROW Code
could have been done in less lines using the .* notation Code
or even better as one line of code using the copyTo method as the datatypes are the same.... Code
or even better it could take advantage of the fact that assignment of dynamic arrays is done by reference ... Code thus the second DISPLAY ARRAY in the multi dialog could be an INPUT ARRAY or a DISPLAY ARRAY with CRUD and changes would be made to tier[tier01_row] Unfortunately I could not think of a way for tier01_flat to be similarly populated by reference from tier01 Reuben Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Sean H. on September 05, 2022, 05:30:35 pm The new and improved code looks really nice and will be a viable way to implement what I am trying to do.
I'm also just puzzling on how to copy arrays that don't have the exact same fields. The only way I've been able to do it is with a dedicated get function function f_get_tier01_flat(tier01) define tier01_row integer, tier01 dynamic array of record t01_id integer, t01_code varchar(10), tier02 dynamic array of record t02_id integer, t02_code varchar(10) end record end record tier01_flat dynamic array of record t01_id integer, t02_desc varchar(10) end record call tier01_flat.clear() for tier01_row = 1 to tier01.getLength() let tier01_flat[tier01_row].id = tier01[tier01_row].id let tier01_flat[tier01_row].code = tier01[tier01_row].code end for return tier01_flat end function Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Reuben B. on September 05, 2022, 11:01:52 pm Quote I'm also just puzzling on how to copy arrays that don't have the exact same fields. The only way I've been able to do it is with a dedicated get function Try something like ... Code
... the util.JSON.parse parses by name and will ignore differences Reuben Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Sebastien F. on September 06, 2022, 08:58:50 am Hello Sean,
Sorry to jump late on this and if I am missing something... First, let's call a spade a spade. You original structure: Code
Is not exactly what we call a "multi-dimensional" array. Multi-dimensional dynamic arrays are defined by the "WITH DIMENSION" clause, see Syntax 2 in: https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Arrays_002.html Example: Code
In your structure, you define a sub-array, as a record element of the main array. To me this is an indicator that there is a relationship between sub-rows and main rows. Are you sure you want to control these separate sets of rows in individual DISPLAY ARRAY dialogs? Would your structure not better be displayed in a TREE view? https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_treeviews_001.html Seb Title: Re: Using Multidimensional Arrays with Screen Array Displays/Inputs Post by: Sebastien F. on September 06, 2022, 12:49:23 pm While working on a sample using a tree view, I saw that the ids of the sub-array (t02_id) can be equal to the ids of root/parent rows (t01_id) ...
let tier01[1].t01_id = 1 let tier01[1].t01_code = "T1-1" let tier01[1].tier02[1].t02_id = 1 Is this really the case? This would be a blocker to implement a tree view. But if you can produce ids that are unique, it's possible (see attachment) Seb |