I’m pretty new to coding, even low-code versions of coding, so i might be missing something obvious here.
I have many docs where I use a button within a row to create a page associated with that row. It names the page after the row display value, and inserts a link to the page into the row as well. This all works well.
When selecting the ‘parent page’, for most of my docs this is based on some category, like current status, or type. There’s usually 2-5 different ‘parent pages’ I might want to use, and so I code the button with a switchif() function, just duplicating the entire page creation formula but directing it to a different parent page. Works great.
The issue has come up where I’ve create a doc where I have 26 parent pages (A, B, C, D, ). The table is a list of films, and I’d like each page to be put in an alphabetical bin based on the film title.
So doing my usual thing would require not just duplicating the formula within a switchif() 26 times (for each letter), but closer to 79 times (specifying rules for each letter, then again for each letter starting with A or The).
I won’t paste the whole long code, but this is the basic idea of how it’s working:
`Switchif(
Left(thisRow.Name, 5)="The A",
ModifyRows(thisRow,thisRow.Page, DuplicatePage([Single Film Template], name: thisRow.Name, parentPage: A)),
Left(thisRow.Name, 3)="A B",
ModifyRows(thisRow,thisRow.Page, DuplicatePage([Single Film Template], name: thisRow.Name, parentPage: B)),
Left(thisRow.Name, 1)="C",
ModifyRows(thisRow,thisRow.Page, DuplicatePage([Single Film Template], name: thisRow.Name, parentPage: B)),
)`
I created a version of this, and while it makes the formula editor freeze a lot, it does actually work when I press the button.
However I thought there needed to be a more efficient way, so I tried to do it with a formulamap() function. I created a table with a row for each potential (A, B, The A, The B, An A, etc) as well as the associated page in a different column.
This almost works, but the duplicatepage > parentpage function will not accept row/column data when it’s expecting a page. Even if that row/column is returning a single page, it doesn’t parse right.
Any ideas? I can keep using my janky extremely long formula, but I’m not looking forward to going back to edit it if I need to! lol
edit: I was able to reduce it significantly (and make it case insensitive) by stacking the conditions pointing to the same page with OR, but it’s still really long.
Switchif(
Upper(Left(thisRow.Name, 3))="A C" OR upper(Left(thisRow.Name, 5))="THE C" OR Upper(Left(thisRow.Name, 1))="C",
ModifyRows(thisRow,thisRow.Page, DuplicatePage([Single Film Template], name: thisRow.Name, parentPage: C)),