How to automatically associate two records

  • KM03630771
  • 26-Mar-2020
  • 27-Mar-2020

Summary

How to automatically associate two records

Question

How to automatically associate two records to get displayed under related records?

Answer

Add the following code into after add trigger that creates the first record that will create a relationship with the existent one

var relation = new SCFile("screlation");
relation.source = record.id; -- where id is the name if the field that stores the record ID
relation.source_filename = "table1"; --- table1 should be replaced by the master table of the record just created
relation.depend = record.relationid; -- where relationid is the name if the field that stores the related ID record
relation.depend_filename = "table2"; --- table1 should be replaced by the master table of the related record to associate

relation.type = "Related";

relation.doInsert();