Change in linking records in script

Viewing 5 reply threads
  • Author
    Posts
  • March 15, 2026 at 6:00 AM #53669

    Mark Moran
    Participant

    I’m not sure it’s the latest 1.1 update or the fact that I just restored from a backup. But this script used to create new record in another form and link it and display it immediately in the record. Now I have to go out of the record into the other form and then back for it to show up. Is it my script or has something changed in Tap Forms Pro?

    
    function CopyToEbaySales() {
    
        // --- 1. CONFIGURATION ---
    
        // A. Source Fields (From COINS Form) - HARDCODED IDs
        var coin_type_id = 'fld-1231556e0f234de9b2d85f50225b8135';
        var year_id = 'fld-4b84b047badd4d4cbb4a67ef6839522f';
        var mint_id = 'fld-adb0be16f1a347dbbecc4ef562d779a7';
        var photo_id = 'fld-d32730d871864ab2904cb60c587b105a';
        var purchase_price_id ='fld-6deb90149d2b494fa3a3e89236398857';
    
        // B. Destination Fields (From EBAY SALES Form) - HARDCODED IDs
        var ebay_coin_type_id = 'fld-9fdddd3a7a47410394042488e730f6c0';
        var ebay_year_id = 'fld-6bee0d6f1e2b413192715c2c807d526f';
        var ebay_mint_id = 'fld-cc42485d28c14c99bbd4970619bee9cf';
        var ebay_photo_id = 'fld-e4a157a02f4841dc845b3ce800565c8e';
        var ebay_cost_id = 'fld-dfa5d5683deb466e9a8088d2d4db56a5';
    
        // C. Link Field (From COINS Form) - DYNAMIC LOOKUP
        // We get this ID automatically using the name. 
        var link_field_name = "Ebay Sale";
        var link_field_id = form.getFieldNamed(link_field_name).getId();
    
        // --- 2. EXECUTION ---
    
        var ebayFormName = "eBay Sales";
        var ebayForm = document.getFormNamed(ebayFormName);
    
        if (ebayForm) {
            
            // Create the new record in eBay Sales
            var newEbayRecord = ebayForm.addNewRecord();
            
            // Copy the data
            newEbayRecord.setFieldValue(ebay_coin_type_id, record.getFieldValue(coin_type_id));
            newEbayRecord.setFieldValue(ebay_year_id, record.getFieldValue(year_id));
            newEbayRecord.setFieldValue(ebay_mint_id, record.getFieldValue(mint_id));
            newEbayRecord.setFieldValue(ebay_cost_id, record.getFieldValue(purchase_price_id));
    
            var photos = record.getFieldValue(photo_id);
            if (photos) {
                newEbayRecord.setFieldValue(ebay_photo_id, photos);
            }
    
            // Link the new record back to the current Coin record
            if (link_field_id) {
                record.addRecordToField(newEbayRecord, link_field_id);
            } else {
                console.log("Error: Could not find a link field named '" + link_field_name + "'");
            }
    
            // Save
            document.saveAllChanges();
            console.log("Success: Record moved and linked.");
            
        } else {
            console.log("Error: Could not find form named " + ebayFormName);
        }
    }
    
    CopyToEbaySales();
    
    • This topic was modified 1 month, 2 weeks ago by Brendan.
    March 15, 2026 at 6:43 PM #53688

    Brendan
    Keymaster

    Try using document.saveAllChangesAndRefresh();

    That’ll refresh the record when you save.

    March 17, 2026 at 11:01 AM #53714

    Mark Moran
    Participant

    Thanks that did it. Any reason can see that the year field doesn’t copy over. I’ve doubled checked and copied and pasted the field ids. All the other fields populate.

    March 17, 2026 at 11:28 AM #53719

    Brendan
    Keymaster

    I edited your post to make the code more readable. Just put a back-tick around it. One at the beginning and one at the end. The forum will format the code to make it easier to read.

    Anyway, I don’t see anything wrong with your script.

    Try putting a console log message before: record.getFieldValue(year_id) to see what you get:

    console.log(record.getFieldValue(year_id));

    March 21, 2026 at 10:50 AM #53751

    Mark Moran
    Participant

    Strange I added two lines.

    newEbayRecord.setFieldValue(ebay_coin_type_id, record.getFieldValue(coin_type_id));
    console.log(record.getFieldValue(year_id));
    newEbayRecord.setFieldValue(ebay_year_id, record.getFieldValue(year_id));
    console.log(record.getFieldValue(ebay_year_id));
    newEbayRecord.setFieldValue(ebay_mint_id, record.getFieldValue(mint_id));

    3/21/26, 1:48:22 PM / Coins / Create Ebay sale
    1917
    undefined
    Success: Record moved and linked.

    The FLD id is correct.

    Attachments:
    You must be logged in to view attached files.
    March 21, 2026 at 8:37 PM #53762

    Brendan
    Keymaster

    Isn’t your ebay_year_id field in a different form from the form record is in?

    You’re setting the value on newEbayRecord, but then you’re reading it from record.

    ebay_year_id is not a field on your record form I would assume.

Viewing 5 reply threads

You must be logged in to reply to this topic.