Update a list from a table using API

Options
Have a table (source) the has a list reference from another table (program). How can I update the program list in the source using API? Have source_id and program_id as inputs.
Thanks in advance,
Emilio[update_table_list_reference_061421.jpg]

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hey Emilio, it depends on how you want to update that list... do you want to replace it with a new list or do you want to add to the existing list? 
  • Emilio Carranza
    Options
    This is a list of programs for a source.
    [source_program_list_061421.jpg]This page shows the list of programs for a source. If I click the green +, I want to add the program (Dual Enrollment #6) to the list, If I click the red delete, I want to remove the specific program from source.
    [source_program_update_list_061421.jpg]So probably add to list and remove from list?
    Thanks
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Here's a quick tutorial on merging arrays:
    https://www.loom.com/share/79ff965fa7784ff3949e18c5ca1ed219
  • Emilio Carranza
    Options
    Awesome! Worked perfectly. Now I tried to use remove array to remove a program_id from source table. Did not work. Darn. What am I missing?
    [source_program_rmv_061621.PNG][source_program_rmv2_061621.PNG][source_program_rmv3_061621.png]
    Thanks for all your help!
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    If you are just removing one element at a time, then change the input structure to single instead of list and use the remove filter. However, if you can remove multiple elements at a time from the array then I'd use the Find All Elements function to update the array - here's another quick video on that:
    https://www.loom.com/share/4b0969b13b4141c19cef75957b4bd795
  • Emilio Carranza
    Options
    Thanks so much. This is very enjoyable. 
  • Marianna Kerppola
    Options
    Hi ! I tried following the Loom video above to add a new object to an array, but couldn't get it to work. I tried to add the new object with push, append and merge without any luck. Here's a loom video showing the endpoint and set up: https://www.loom.com/share/56382ac7b9fe44e3813e0782b0b01b40

    Thanks for your help!
  • Marianna Kerppola
    Options
    HI  ! I've made new attempts to update user with a new linked record, but the new record never ends up in the array. Occasionally, a new item will be created in the array, but it's blank. Here's a video showing the various scenarios I've tried: https://www.loom.com/share/c8dab85384ce4a9f85b63fb08cb134e9
  • Emilio Carranza
    Options
    
    Good morning Marianna,
    Took a quick look. Here is an example of adding a item from another table (requirement) into a list in another table (activity). This is working for me. For the Inputs I used integer[] not object[].
    [marianna1.PNG]I merged requirement_id as shown.
    [marianna2.PNG] Maybe do a Get Record after the Add Record from childinfo?
    Or course Michael will set you right. He has helped me sooo much! 
    Have fun Xanoing!
  • Marianna Kerppola
    Options
    Thanks ! Great catch! How did you switch it to an integer[] from object[]? It automatically came through the database as an object[]. When I click on it, I find the integer[] field for the id, but each time I try to add it to my inputs, it disappears... Not sure if it's a bug, or if I'm doing something wrong. Here's a video demonstrating this: https://www.loom.com/share/dd7a590ba1a0415eb16c4b20c4fcc75d

    Thanks for your help! 🙏 
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     Emilio has a different schema structure than you as he was just dealing with a scalar array (an array of integers in this case). You are dealing with an array of objects. Objects are handy if you need to contain more data (fields) to describe something. If you have just one field in your object array - and never see a need to add additional then I might consider using just an array. However, if there is more information you'll need to store or think there eventually might be then keep the object structure. Nonetheless, here's a video on how I'd go about updating an object array for your example: 

    https://www.loom.com/share/2c37acf093b8476e8ca8497301c4a56d
  • Marianna Kerppola
    Options
    Hi ! This is a helpful Loom video, though I'm still not able to get it to work. I'm running into an "unknown error" when trying to run and debug, so I can't see any debugging info.

    The specific step I'm stuck on is selecting the "path" with the "set" filter. I understand the path should be the object within the get record output, but I'm not able to find that option in the dropdown menu.

    Here's a video showing both the unknown error, as well as the rest of my set up: https://www.loom.com/share/7cf69f8017dc4fc0b39bcef44456723a

    Thanks for your help!
  • Marianna Kerppola
    Options
    Hi ! I set the path as text, and it worked! Now I'll need to figure out how to combine this with adding a new child in the same stack. 👍
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Nice! Yup the path will typically just be text in the majority of use cases since you're just defining the path (or think of it like a field in an object or table, which are static and are described by a value). The values are normally going to be variables or inputs because those will more likely be dynamic. Glad you figured that out ahead of me seeing this
  • Vince
    Vince Member
    Options
    This was useful to me guys. +1.

    On top of this I also would add the filter at the end "UNIQUE" to make sure the data merge doesn't contain duplicate of the same data (depends on your use case, but if you're even just testing something twice it will just add over and over the same record).[CleanShot 2022-05-07 at 11.33.04@2x.png]