How to Copy Reference List using Action Button

Hi,

I am attempting to use the Action Button to copy a record.

Currently I can copy the following field types successfully,

  • Standard fields using $column_name
  • Reference fields using $column_name.id

However, when attempting to copy a Reference List type field to a new record, i receive a the following errors,

  • “Experiments”: $Experiments, # {‘rowIds’: [1], ‘tableId’: ‘Experiment’} , gives this error
  • “Experiments”: $Experiments.id, # KeyError, gives this error

$Experiments field is a Reference List within the Sample table, linked to Experiment table.
The action button is linked to a field in the Sample table

#action button linked field within Sample table

actions = []

# Adding Samples
actions.append(
  ["AddRecord", "Sample", None, {
    "Experiments": $Experiments,  # {'rowIds': [1], 'tableId': 'Experiment'} , gives this error
       # or if we use *.id
    "Experiments": $Experiments.id,   # KeyError, gives this error
    "Process_ID": $Process_ID.id,  # Reference Field, works as expected
    "Tests": $Tests,   # Standard Field, works as expected 
    "Results": $Results,
    "Repeats": $Repeats,
  }])
  
return {
  "button": "Duplicate {} records".format(len(actions)-1),
  "description": 'Duplicate "{}" records from {}'.format( len(actions), $Process_ID.Process_Name),
  "actions": actions,
}

Any help would be much appreciated.

Thank you for a fantastic product and very proactive engagement!!

Solved

Action Button’s AddRecord expects the Reference Field in the format shown here,

"[index_num_1,index_num_2,......]" 

This can be achieved by creating a list of the Reference Field and converting it to a String

str(list($Experiments.id))

with the final code looking like:

#action button linked field within Sample table

actions = []

# Adding Samples
actions.append(
  ["AddRecord", "Sample", None, {
    "Experiments": str(list($Experiments.id)),   # Reference List , works as expected
    "Process_ID": $Process_ID.id,  # Reference Field, works as expected
    "Tests": $Tests,   # Standard Field, works as expected 
    "Results": $Results,
    "Repeats": $Repeats,
  }])
  
return {
  "button": "Duplicate {} records".format(len(actions)-1),
  "description": 'Duplicate "{}" records from {}'.format( len(actions), $Process_ID.Process_Name),
  "actions": actions,
}