Update specific items in an array

Options

Hey, I have watched a few of the Customer Corner videos now re updating/editing arrays through the API, but I'm struggling to apply them to my situation. I've recorded this loom, but will give a quick overview here too:

The frontend user

I have a page in my app where users can update the 'Core' for their brand, e.g. the Purpose, Vision, Mission and Values statements.

On the Webflow front-end, these are form fields where users can click and type and it automatically updates. I've set it up between Webflow/Wized/Xano to do all the single text fields (Purpose, Vision & Mission) but I can't work out how to do it for the array of values.

Users can have one of any five 'values' for their brand.

Each value consists of the 'one word' term for it and the descriptive text, e.g.

  • (One word : text)
  • Systems thinking : we need to understand the entirety of a business before consulting
  • Respect : we need to be more like Aretha Franklin
  • Local pride : we are good citizens of Narnia

etc

Say a user only wants to change "Local pride" to "We love our home". Nothing else needs to update.

The API

I saw this video where it was showing how to update opening hours by finding, for example, "Monday" and updating the associated opening and closing hours. But if the first item in the array is also subject to change, how do I reference it?

I'm sure I'm missing something simple, but simple is as simple does! :)

Tagged:

Comments

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hi @NicelyPutEllie! I think the video linked at the end of your post should help here. Using the Get Record to first retrieve the existing data, and you can then use an Array: Find First Element Index to find the element in the array that matches what the user is updating (this means you'll need your front end to send the old data as well as the new), update it in the variable and then edit the record in the database.

  • NicelyPutEllie
    Options

    Thanks Chris! I hadn't considered having the front end send the old data as well as the new. I did post an update where I decided to update the schema in the Xano object to set an integer ID so that it was easier to reference, especially as users can't change that. For some reason that didn't post!

  • NicelyPutEllie
    Options

    I've been doing more research. I think the way forward might be:

    Create an auto-incrementing 'ID' for each 'Values' item so that each one within each brand record will have its own reference ID that the user can't change:

    Then use the process in this tutorial to update any items that have been edited:

    Does this seem right? It feels clunky but I don't know enough to know what I don't know!