Dynamic Control Selection and Setting in Formulas After Duplicating Pages

Hello Coda Community,

I’m working on a use case in Coda and seeking insights or potential solutions. Specifically, I’m looking to dynamically select and set the value of a control after duplicating a page, using a formula. My goal is to use a formula to not only set the value of a control but to dynamically determine which control to set.

Scenario:

After duplicating a page, I want to automatically set a control’s value on the newly created page. I can dynamically retrieve the last control using something like [Control List].last() from Doc Inspector
, but I’m struggling to dynamically set this control without hardcoding it.

Question:

Is there a way to use SetControlValue() in such a manner that the control itself is selected dynamically? Something akin to:
‘’’
SetControlValue(<[Control List].last(), n)
‘’’
where [Control List].last() dynamically identifies the control to be set.

I appreciate any guidance or workarounds you might suggest, especially if you have tackled similar dynamic scenarios in your Coda documents.

Thank you!

Welcome to the community @raggi_eth.

Two thoughts came to mind.

  1. In the control value, you can set the ‘Starting Value’ using a formula, that means we can use your formula. The only thing I’m not sure about is upon reload, if it will use that starting value.

  2. You can use SetControlValue() in a button, so technically, can use RunActions() to duplicate a page and then set the control value.

If you have a sample doc, please share it and I will be happy to test the above 2 scenarios out.

Hi boonshin!
thanks for your reply.

I tried setting the default value for a formula, I created a helper table with a counter that I iterate before page duplication. then use the value as the default value for the controls. the problem is that this affects all the controls. so after I duplicate again all controls on the duplicated pages are set to the new count.

in the other solution SetControlValue() with a button, I still need to be able to reference the control value. I know I can set it after the fact by hand but im wondering if I can use Control list table from the Doc Inspector pack rows to reference specific controls in my page.

for example here I was testing if SetControlValue(thisRow.Control,1 ) would work.
it trows an error
SetControlValue expects parameter control to be a control, but found value (‘text 7’), which is an object

im wondering if there is a way to somehow convert this object into a reference to the control

Hi @raggi_eth, it would be helpful if you can share the doc with me. I’m not clear where your control is and it’s hard to get the whole context with a screenshot.

boonshin solved the problem, instead of duplicating the page and trying to set an unknown control, the control on the template is set before duplicating the page!