Home > Forum > Forms > Item list and adding new items with Javascript

Item list and adding new items with Javascript
0

Hi all!

We are wondering if there is a good way to add new items to an item list on the client side.

We already found a way to add new item (which can be triggered by a form rule) and set some form fields before, which then act as default values for the new row.

Since it all is asynchronous it has to be a promise chain, like this pseudo code:

p.then(() => { SetValue(formField, 'Value') }).then(() => { InvokeRule('#{BRUX:1526:ID}#') })

This is working fine but unfortunately this seems to be incredibly slow, if there is a larger amount of rows to be added.

We tried to call item lists initialize, but that seems to replace all items in item list, which we don't want.

Maybe there is a way to initialize (with some sort of UNION query) which takes respect to existing items and also adds new rows.

I hope you understand what we are looking for and trying to achieve.

Looking forward to your experience.

Thanks in advance & best regards, Nik

MVP

Hi Nik,

I also would like to have a "Add new row with values" function but I haven't had the time yet to look for a solution.
Regarding the initialize option. I'm using this in a similar situation.
The source of an item list may be changed over time and the item list has to reflect these changes in a step. Therefore I'm calling the initialize action during Onload and the SQL query gets all rows and joins them with row values which have been set by a user. In my case rows could be added or be deleted in the source.

There's maybe one drawback, it works only with a saved item list. If you would initialize it multiple times without saving the intermediate changes will probably lost. Of course you also get new DET_ID so your history may be a mess.

Best regards,
Daniel

Hi,

there is the possibility of using an existing SQL procedure in the content database. It is called "proc_WFElementDetailsInsert". It is difficult to set up all the parameters for this, but then it works very quickly and reliably. There is a suitable function for deleting it, it is called "proc_WFElementDetailsDelete". A replacement can also be implemented from a combination of both procedures.

MVP
In reply to: Ralf Kühne (VSB)

Hi,

there is the possibility of using an existing SQL procedure in the content database. It is called "proc_WFElementDetailsInsert". It is difficult to set up all the parameters for this, but then it works very quickly and reliably. There is a suitable function for deleting it, it is called "proc_WFElementDetailsDelete". A replacement can also be implemented from a combination of both procedures.

Hi Ralf,

while I'm glad that an experienced partner joined the community I'm baffled by this suggestion.

I'm currently on vacation so I can't check it but those procedures I had a look at, did exactly what the name implied. Insert/Update/Delete of an entry in the table. I assume it's the same with the mentioned procedures. Therefore I would assume that you loose the history and therefore one of the great strength namely audit/traceability?

While I personally wouldn't use internal functionality which modifies data, you could achieve something similar using the default action to change an item list and use a custom SDK action for deleting speicif rows.
https://daniels-notes.de/posts/2022/remove-item-list-rows

Best regards,
Daniel

MVP
In reply to: Ralf Kühne (VSB)

Hi Daniel,

if you use Jva Script for this, traceability might also become problematic. The actions for adding, removing and changing item list entries only work on a per-instance basis. If you want to add an entry "from outside", these do not work. (e.g. assume a for-ech automation)
With the SQL procedures, the changes in the item list are at least visible, even if not under the name of the executing person.
Finally, there is still the use of the WEBCON REST API ... which can also be used to create item list entries.

Best regards,

Ralf

Hi Ralf,

you have a point there. I was focused on the fact that less experienced users will read this and may do something which cause undesired side effects. On the other hand, non experienced users won't be able to use the procedures.

I'm wondering whether this would be possible with R3
From the change log:
Changed the scope of privileges and the dedicated database read
account.
The change applies to systems where a dedicated Database read account
was defined during installation (the account for which SQL COMMAND rules
and all SQL queries using Default connection are executed).
When upgrading the system to the latest version, a database user named
BPS_User will be created in all content databases with read permissions for
selected tables and views. If a BPS_User user exists in the database, their
privileges will be extended accordingly. The detailed scope of privileges
granted to BPS_User is available in the dbo.proc_GrantLowPrivileges()
stored procedure.
After upgrading the system, all queries performed so far by the system in the
context of the dedicated Database read account will be executed in the
context of BPS_User.
For newly created installations, all queries using the Default connection and
queries executed in SQL COMMAND rules will always be executed in the
context of BPS_User. It is not possible to change this behavior.

If I understand this correctly, any query will be executed with the read account and it won't be possible to execute and modification query. At least without changing the permissions of the user yourself.

Best regards,
Daniel