Creating a record with a link to another record with script

Hi!

Is it possible to create a record using script so that the created record linked to another record, for example through record ID? This works well with import but with script I am having problems.

I have the following type of basic script which works if the linked field is excluded (I’ve tried with hard-coded values too)

const insertAccounting= await doo.table.createRecord('table', {
    documentTitle: doo.model.value,
    documentType: doo.model.value,
    **linkedRecord: doo.model.ID.value**
    }, 'app')

I get the following error in Workflow Automation:
"Response {\n size: 0,\n timeout: 0,\n errorData: { errors: [ [Object] ] },\n errorsPatch: [\n {\n type: ‘warning’,\n id: ‘badValueTypeValidationException’,\n message: “Bad value type - the expected value type of field ‘linkedRecord’ (schema_link) is Link object or ‘null’ value.”,\n

Hi Martti,

the “Link to table” field in scripting (as well as in API access) expects an object to be updated/inserted - in your case it will be:

...
linkedRecord: { id: doo.model.id }
...

For more information about “links”, see here.

Regards,
Jan

Awesome, thanks Jan!