Can Apps Scripts Populate Link-To-Parent Fields?
I am trying to populate a Link-To-Parent fields via Apps Script and nothing happens.
If copied the format from Drop-down fields, Application User, and Application User Group fields (thinking they would all behave the same), but although the Scripts saves with no errors, and the records can be updated with no errors, the LTP field is not being populated.
If this is possible, can you provide a sample of the code that I can use?

4 comments
-
Matt Cox commented
It is possible to have an app script link a record to a parent. I did it on the child table. You just have to know the parent record ID.
So if Parent Table 1 creates a record in Child Table 1 have an app script on Child Table 1 to create the link to Parent Table 2. (if that makes sense and is even what you are looking for)
Below is the code I used.
Map record = loadRecord(Parent Table Name, Parent Table Record ID Name, Parent Table Record ID Value) as Map
currentValues[Relationship Name] = record;
you just have to be able to create the parent record ID value using information from the child table the app script is on. You have to be creative since app scripts cannot pull in information from calculated fields.
-
Skip commented
This would be an amazing feature!
Any solution to automate/calculate links would be very helpful. -
John McGarvey commented
Hi Alex,
Some clarification.I am trying to populate a LTP field (not single line) via App Script at the same time the script is creating a child record. The child record is being created fine. The LTP is to a second parent table than the one that ran the script to create the child (this would already be auto-joined).
I tried following the format of other "drop-down" type fields (drop-downs, User fields, and User Groups) thinking the format would be the same, but I am not able to get the LTP field in the child record to populate.
There isn't any IF condition to evaluate as the will identify the actual value to enter into the field for each child record being created.
-
Alex commented
Hi John,
Application User and User Group fields are links to other tables in the system so they do behave differently than your standard single line field. This may be why the fields are not working as desired when trying to use them to link to a parent record.
The script code to reference those fields is below:
GROUPS:
Map group = loadRecord("XVIA_USER_GROUP", "group_name", "group name goes here") as MapUSERS:
Map user = loadRecord("XVIA_USER", "email", "user's email address goes here") as MapAdditionally, the script template below can be used to auto link to parent when the parent record ID is comprised of more than one field:
Map parent = loadRecord('parent table name', [parent field to match: currentValues['child field to match'], parent match 2: currentValues['child match 2']])
if (parent) {
currentValues['Link to parent'] = parent
}Hope this helps!
Alex