yuuvis® RAD Q&A

0 votes
by (640 points)

In documentation there is a nice sample on how to clone, manipulate and update table data:
https://developer.enaio.org/redline/display/onpremise/Client-side Form Scripting#Client-sideFormScripting-TABLE

It works well on 3.36 version, but after upgrading to 4.12, the access to the stored data in table is missing or is placed somewhere else.
What I mean is that in version 3.36

scope.model.table.value

returned array of table row objects

[
  {column1: value1A, column2: value2A },
  {column1: value1B, column2: value2B }
]

but in version 4.12

scope.model.table.value

returns not an array, but object with a single key "$mobx" and deep nesting of objects/functions where I failed to find the real values of table data.

Please help with information on what is the new way to manipulate the table data entries by using form-scripting?

2 Answers

0 votes
by (1.9k points)

I have just checked it in a 4.12 system and "scope.model.tablefield.value" still gives me an array with all the values of the table.
Have you checked with the developer tools of chrome or firefox how that object (scope.model.table) looks like while debugging?

by (640 points)
Yes,
  that is exactly how I found out that there is no array, but an object with single '$mbox' key.

here is the link to screenshot image:
https://cdn1.imggmi.com/uploads/2019/7/24/03276174abb273c1d4e738c42ab71dde-full.png

Tested on both Chrome and Firefox dev.tools = same results.

Just discovered one more strange  behavior: if I parse table object to JSON and parse it back to Javascript object, I got all the values I need.
e.g. JSON.parse(JSON.stringify(scope.model.tabcapexclass));
Like it was supposed to work on the first hand. Will check on that more, maybe that will be sufficient for my needs.
by (1.9k points)
I checked firefox and it looks a little weird. But if you open the prototype-Member instead of the $mobx-Member you can see the array there.

Also, using scope.model.table.value[0] correctly returned the object containing the values of the first row of the table in both firefox and chrome.

So maybe it's only a visual thing when it comes to firefox regarding that. The functionality should not be affected.
by (640 points)
Yes, I can read the length of array, with scope.model.table.value.length and get a single row with scope.model.table.value[0], but I can't get the whole array with scope.model.table.value.

Can you share the component version of your 4.12 client? E.g. mine is the 5.7.29 - the newest available.

I also checked that 5th (5.6) client hasn't got this issue, so maybe that issue wasn't there also in earlier 4.12 component versions?

I also have another issue with this client - it doesn't trigger 'onchange' event when I change field's value with script.
So now I am starting to think either of upgrading to 5th client or downgrading the 4th client to some earlier component version, and your version looks to be fine candidate for that...
by (640 points)
My mistake: going up to 5th client doesn't solve the situation with reading whole table data - it did change the structure of the visible information in dev console, but the situation is the same - can't read whole table.

Did some more research, I think now I understand how this works:
1. the mobx library is used in client application to convert form field data structures as observable entities, which registers their state changes
2. in result field values and other config properties are not stored in their original places as it was in 3.36, but mobx is taking care to get/set them on request
3. this technology works instantly if values are simple or a fragment of an object, but if you need to get whole array then it doesn't work so. Here are some discussions regarding it on mobx github site: https://github.com/mobxjs/mobx/issues/1653
4. for such cases there is additional tool in mobx 'https://mobx.js.org/refguide/tojson.html', which in essence does something similar to a 'hack' I was mentioning before with JSON.parse(JSON.stringify(scope.model.table.value))
by (640 points)
Still the question of the topic is not answered:
How to read with script whole table data in client 4 and 5?
Because scope.model.table.value doesn't return it.
Is there a proper way on how to do it or the 'hack' approach I found earlier is the only solution for that?
0 votes
by (640 points)

Update:

I had contacted support and they issued a change request (DB-3762) to restore the missing functionality.
Can't tell yet, but I hope that it will be fixed in 4.12 as well, not just in newer versions.

...