Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms Pro › Changing Parent Record via Script?
- This topic has 8 replies, 3 voices, and was last updated 1 month, 1 week ago by
Shane.
-
AuthorPosts
-
November 23, 2025 at 9:25 AM #53279
ShaneParticipantHey all, so far I’m excited about the power of scripting in TapForms and am trying to put it to good use.
I’m trying to create a template system where I can copy/move placeholder records to a new parent record. Normally to assign a child record to parent record you would click the “Select and link existing records” object/ button which would bring up the possible parent records for reassignment (see screenshot). I’m wondering if this could be done through scripting.
In this example I have a Clients parent form linked to a child Projects form.
You can seem to access the parent record by doing the following (see second screenshot):
function Reassign() { var clients = record.getFieldValue('fld-25ab19edf2014cc0952446ed09975851'); console.log(clients); } Reassign();Console shows a record object:
2025-11-23, 8:02:35 AM / Projects / Reassign
[object CDRecord]So can we somehow code a different parent record for the child record somehow?
Thanks.
Attachments:
You must be logged in to view attached files.November 23, 2025 at 9:37 AM #53282
Daniel LeuParticipantI agree, the scripting feature is very powerful. Without it, I wouldn’t use TFP.
You can add a linked record using
var newRecord = record.addNewRecordToField(field_id);and to remove an existing record there’srecord.removeRecordFromField(childRecord, field_id');. Here’s the link to the documentation https://www.tapforms.com/help-mac/pro/en/topic/javascript-api.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 23, 2025 at 10:11 AM #53284
ShaneParticipantThanks for the reply.
I did read that documentation, but isn’t that used to add a child record to a parent record? I was referring to changing the parent record to the child record.
I guess if I wanted to copy template children to a new parent I could do it that way. I could use a script to essentially copy the child record info from a template parent record and recreate those children records under the new project name. However, I am still curious if you could use a script to change the parent record of a child record. :)
-
This reply was modified 1 month, 3 weeks ago by
Shane.
November 24, 2025 at 2:29 PM #53294
BrendanKeymasterThere’s also the
record.addRecordToField(someRecord, field_id);function which lets you add an existing record to a Link to Form field. So it doesn’t have to be a new one. And if it’s a One-To-Many, then that essentially moves the record since you can’t have a child record belong to more than one parent with that link type.November 26, 2025 at 6:46 PM #53312
ShaneParticipantThanks Brendan, I’ll give that a try.
December 7, 2025 at 12:15 PM #53342
ShaneParticipantHi Brendan,
I tried this method but I keep getting the error “TypeError: Argument does not match Objective-C Class, line:(null)”.
My document’s form schema is essentially: CLIENTS -> PROJECTS -> TASKS (parent -> child -> child). Essentially I’m trying to copy a TASKS record I have currently selected, to another PROJECTS (parent) record. I’ve selected a record in the Tasks form, and executed the following script where the destination record is another project (parent) record, and the destination field is the PROJECTS -> TASKS Link To field:
`function Copy_Record() {
var destinationRecord = “rec-82855338485542a89c1946c3e2cff83e”;
var tasksField = “fld-c2f532ef6611450abf973d5e7297b475”;
record.addRecordToField(destinationRecord, tasksField);
document.saveAllChanges();
}Copy_Record();’
Any obvious errors I have done? Thank you!
December 7, 2025 at 8:19 PM #53344
Daniel LeuParticipantAs you have defined it,
destinationRecordis a record id, but the function needs a record.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksDecember 8, 2025 at 9:35 PM #53346
ShaneParticipantOh yes you’re right, it should be a record object, not a record ID. Thanks.
-
This reply was modified 1 month, 1 week ago by
Shane.
December 9, 2025 at 9:56 AM #53348 -
This reply was modified 1 month, 3 weeks ago by
-
AuthorPosts
You must be logged in to reply to this topic.