Copy Data from Source App into a table in Destination App

Hello Everyone,

I need some guidance. I would like to be able to copy data from one app to a table in another app. I have 2 apps:

App1 - Destination App
App2 - Source App

App1 has a table that I would like to populate 4 text boxes of data from a record from App2 that has same number of text boxes. I would like to use a Text box to have the user (trigger) type in the data needed. Either they would type in the BC# or the Description to find and populate data from that record.

App2 is an app that has 1100 records of data (BC#, Size, Type, Description) per record, it is for labels we use on our products.

The idea would be the user inputs for example either 67000 (BC#) or Label X (Description) and it would populate the same fields inside a table on App1. Then if needed they could press the add button on the table and do it again(there could be multiple entries in one table).

Right now I'm using the lookup and related record feature with some code to hide everything that is not needed (there are multiple selections of product types) but I would like to clean it up and use tables instead.

I been playing with some code with API (Get, Put, etc.)topics from here but with no luck, I'm new to API calls, etc.. Right now just trying to get one field to copy into a text box NOT in a table but no luck.

App2 Example:

App1 Label section (Current):

App1 Label Section Wish List:

Any advice/code example would be greatly apricated. Thank you.

Hello @dpoetsch,

Have you explored App Actions? This feature allows you to copy record data, including tables, to a specified app. If you haven't tried it yet, I recommend giving it a try to see if it meets your requirements.

Hi @Chris ,

Thank you. I have looked into it but I need to pull instead of push. I need the call to come from the destination app (App1) in the Label section of the app. The related records works well but looks messy to me. i was hoping to figure out a way to get the data FROM the Label App record (App2) to the destination app (App1).

Hello @dpoetsch
Here's an example script that automatically retrieves matching IDs from App A and populates table fields in App B when the ID field in App B is entered.

(function() {
    "use strict";

    // Define App IDs
    const appAId = ###; // App A ID
    const appBId = kintone.app.getId(); // App B ID is the current app

    // Define Field Codes
    const idFieldAppA = 'ID';
    const colorFieldAppA = 'Color';
    const shapeFieldAppA = 'Shape';

    const tableFieldAppB = 'Table'; // Field code for the table in App B
    const idFieldAppB = 'ID';
    const colorFieldAppB = 'Color';
    const shapeFieldAppB = 'Shape';

    // Event triggers when the record is shown
    kintone.events.on(['app.record.create.show', 'app.record.edit.show'], function(event) {
        // Get the record data
        var record = event.record;

        // Add an event listener for the ID field change in the table
        kintone.events.on('app.record.create.change.' + idFieldAppB, function(event) {
            var record = event.record;
            var table = record[tableFieldAppB].value;

            table.forEach(function(row) {
                var idValue = row.value[idFieldAppB].value;

                if (idValue) {
                    // API request to fetch the record from App A
                    kintone.api(kintone.api.url('/k/v1/records', true), 'GET', {
                        app: appAId,
                        query: `${idFieldAppA} = "${idValue}"`
                    }).then(function(resp) {
                        if (resp.records && resp.records.length > 0) {
                            var appARecord = resp.records[0];

                            if (appARecord[colorFieldAppA] && appARecord[shapeFieldAppA]) {
                                row.value[colorFieldAppB].value = appARecord[colorFieldAppA].value;
                                row.value[shapeFieldAppB].value = appARecord[shapeFieldAppA].value;

                                kintone.app.record.set(event);
                            }
                        }
                    }).catch(function(error) {
                        console.error("API call failed:", error);
                    });
                }
            });

            return event;
        });

        return event;
    });

})();

Thank you @Chris. I will take look at this code and play around with it to get it to work on the app. Again, much apricated that you take the time to "teach" me on this forum. I've always been more on the hardware side of IT but in the last couple of years move more to project management and some minor coding work. Thanks again!

2 Likes