Cloning task in automation - error

Hi, I thought there was an action in button automation to clone current entity (and being able to updare some field), but there’s not - maybe a feature request :slight_smile: , so I found this thread of 3 years ago where Polina showed the JS code to duplicate a record. I used that code as automation action and it seemed to work but at every execution in the activity log, the action is reported as failed with

Failed to execute Action "Script": (intermediate value) is not iterable

followed by the list of field that have been (correctly) copied into the cloned record…
What is wrong or what should I do to catch the problem?
I don’t know if in the meantime there is a simpler method to clone a record (creating a new task and assigning each field value is not an optimal solution since my table has more than 20 fields).
Thanks!

Giuse

My approach would be to add many console.log messages to track the code’s progress, so you can narrow down which line is causing the issue.

I found a first issue in Polina’s script for cloning task: if replacing

    const [{ result: newEntity }] = await fibery.createEntity(

with

    const newEntity = await fibery.createEntity(

one error is solved.
But there is another error I cannot understand how to solve:
Cannot find type for ["$id"] param. Please, ensure that all parameters are passed as 'params' argument to query."
that refers to the query, in particular it seems the last line to throw the error

const newEntityDetails = await fibery.executeSingleCommand(
    {
        "command": "fibery.entity/query",
        "args": {
            "query": {
                "q/from": type,
                "q/select": {
                    "Id": "fibery/id",
                    "RichTextField": {
                        "Id": [richTextField.name, "fibery/id"],
                        "Secret": [richTextField.name, "Collaboration~Documents/secret"]
                    },
                },
                "q/where": ["=", ["fibery/id"], "$id"],
                "q/limit": 1
            },
            "params": { "$id": newEntity["fibery/id"] }
        }
    });

how to fix it? I can then post to the original thread with the fully working version of the cloning script for others interested.
Thank you very much

Giuse

Try this instead:

"params": { "$id": newEntity["Id"] }
1 Like

Thanks Matt!!! Now it works

1 Like