Adding specific data to record only once when 1st object in list is created ?

Options
Fredk
Fredk Member
edited May 2023 in ? Help! I'm a Noob
[
{"type": "preface", "body": "some paragraph"},
{"type": "chapter_1", "body": "some paragraph2"},
{"type": "chapter_2", "body": "some paragraph3"},
{"type": "chapter_3", "body": "some paragraph3"}
]

My function stack adds one record (1 object at a time), then queries all records. But I need to add the preface content only once, when a new book is created. Anyone knows how to do this, maybe with a "conditional" variable?

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Seems like you need to query records beforehand to check if preface one is already there. If you are having a loop for adding the objects then you most likely want to check it outside of itso you are not making the query during every iteration.

    You can query with exists type that return a true or false depending on the existence of a particular records. Based on that you can create a conditional to add the first object with preface if the query is false.

    Hope that helps