Confusion regarding target object in OnForeignInsert Transform Script

yuvraj1808s
Giga Contributor

Does target actually point to the referenced table (like sys_user) at runtime in OnForeignInsert?

If yes, why does the script editor still suggest fields from the main target table?

Is this just a limitation of the editor, or am I misunderstanding something about how Transform Map scripts work?

Any clarification would be really helpful. Thanks!

1 REPLY 1

pr8172510
Kilo Guru

Hi Yuvraj,

Good question — this is a common point of confusion when working with Transform Maps and OnForeignInsert scripts.

A few things you should know:

  1. What target refers to in OnForeignInsert
    Yes — at runtime, target points to the referenced (foreign) table record being created.

Example:
If you are inserting into a reference field pointing to sys_user, then:
 target = new record in sys_user

  1. Why editor shows main target table fields
    This is mainly a script editor limitation.

The editor:

  • Is context-aware only at Transform Map level
  • Assumes target = main target table of the transform
  • Does not dynamically switch context for OnForeignInsert

So it continues suggesting fields from the main table even though runtime behavior is different

  1. What actually happens at runtime
    During execution:
  • Transform detects missing reference
  • Triggers OnForeignInsert
  • Creates a new record in referenced table
  • target object now represents that record

So your script works correctly even if suggestions look wrong

  1. Practical example

If reference = caller_id → sys_user:

target.user_name = source.u_email;
target.first_name = source.u_first_name;
target.last_name = source.u_last_name;

This will correctly populate sys_user, not the main table

  1. Best practice (important)

✔ Ignore editor suggestions in this context
✔ Always verify the reference table manually
✔ Use dictionary to confirm field names