Looping through an array and add to a record with an array field

Options

I have a table called "Sales documents", which has an array of "Sales document lines" ids.

On the frontend, I am able to get the sales line items and then create a variable called "list-ids-only", which returns the following ids (dynamic depending on what the user entered):

I then run a for loop to loop through the sales documents lines ids (above variable) in order to save them to an array (called Invoice_lines) in Sales documents (the record already exists in the database at this point), as follows:

The "edit record in sales documents" looks like this:

The swagger shows that my Invoice lines takes the following inputs:

The results of the loop is only one id and not all ids are saved in the database.

I need to save ALL IDs to the above array, please assist. I am a newbie, not sure if the above makes sense, please bear with me.

The results in my head is that each time I loop through the IDs (variable), the IDs needs to be added to the end and not overwrite the existing ID in the "Invoice_lines".

Answers

  • arturosanz
    arturosanz Member ✭✭
    edited October 2023
    Options

    @Lebohang326 you can't partially store field contents.

    Every time you use the Edit Record function you are saving the entire content of each field you selected to be edited. So it's not a good idea to include the Edit Record function inside a For Loop statement that iterates over the items of a list field. It only makes sense to insert the Edit Record function inside a loop when you need to add several records, but not when you want to add several items to a list field of one record.

    You must build the entire field content first with a For Loop and an Update Variable inside it rather than an Edit Record. Once the entire list is built after the For Loop ended, then you call the Edit Record function just ONCE to store the entire built list into the Invoice_lines list field.