Ask Reuben

Array Methods vs Dialog Methods

What is the difference between array methods and dialog methods with the same name?

Why is my array method not working as expected?

In the list of build-in array methods and ui.Dialog methods there are similar sounding methods to insert, append,  and delete.  These include …


Array MethodDialog Method
appendElement()

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Arrays_ARRAY_appendElement.html

appendRow()

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ClassDialog_appendRow.html

insertElement()

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Arrays_ARRAY_insertElement.html

insertRow()

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ClassDialog_insertRow.html

deleteElement

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Arrays_ARRAY_deleteElement.html

deleteRow()

https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ClassDialog_deleteRow.html


The common mistake is to use an array method when the array is attached to an active dialog.

Simple rule of thumb is that if the array is being maintained by active dialog then you should use the ui.Dialog method and not a ui.Array method.

So for example

DISPLAY ARRAY arr TO ...
...
    ON ACTION my_insert
         ...
         CALL DIALOG.insertElement(...)
         ...

and not

DISPLAY ARRAY arr TO ...
...
    ON ACTION my_insert
         ...
         CALL arr.appendElement()
         ...

The reason it is important to use the dialog method and not the array method is that the dialog method will also maintain the correct appearance of the dialog.  The array method will not necessarily trigger the front-end code for that to happen.