Sending/Passing Subtable (App A) content to Subtable (App B)

Hi Guys,

Can you help with this, I want to pass/post the subtable (App A) data to subtable (App B) I just can’t figure out how to use GET/POST Rest API on this problem.

 

Here is my code:

(function() {

    ‘use strict’;

                

    var events = [‘app.record.create.submit’, ‘app.record.edit.submit’];

    

                    kintone.events.on (events, function (event) {

                        var record = event.record;

                        var product_code = record[‘productcode’].value;

    

                    var body = {

                            ‘app’: XXX,

                            ‘query’:‘prod_code = "’ + product_code + ‘"’

                            }

                        kintone.api(kintone.api.url(’/k/v1/records’, true), ‘GET’, body, function (resp) {

                        var recordd = kintone.app.record.get();

                        var Table11 = recordd.record.TableTestB.value;//Copy table

                        if (Table11.length === 1) {

                        Table11.pop(); //Erase the first line

                          

                        for (var i = 0; i < resp.records.length; i++) {

                            for (var j = 0; j < resp.records[i].TableTest.value.length; j++) {

                                if (resp.records[i].TableTestB.value[j].value.prod_code.value === product_code) {

                                    var DateB = resp.records[i].TableTest.value[j].value.DateB.value;

                                    var NumberB = resp.records[i].TableTest.value[j].value.NumberB.value;

                                   

                            // Add line

                                        Table11.push({

                                          value: {

                                            “DateA”: {

                                              type: “DATE”,

                                              value: DateB

                                            },

                                            “QuantityA”: {

                                              type: “NUMBER”,

                                              value: NumberB

                                            }

                                          }

                                        });

                                      }

                                    }

                    kintone.app.record.set(recordd);

                }

            }           

        return event; 

        });

    });

})();

 

Thank you so much for the help.

Also additional info. what output that I want is when the record in App A has the same Product Code(unique key) in App A then it will add the subtable content in App  B’s subtable.

Hello Muhaymin!

Since you can’t use = against tables, is the error occurring in the query?

Also, it seems like you are using the SET function to set up the value from the GET process within the SUBMIT event. About the SUBMIT event, since it changes to the record view page after the event finishes, by the time the SET function that moves within asynchronous process triggers, you are internally already at the record view page, so the value might not be appropriately set up. So it might be much better to use PUT API to update records.

Kintone Developer Program - Update Record
https://developer.kintone.io/hc/en-us/articles/213149027

Kintone Developer Program - Update Records
https://developer.kintone.io/hc/en-us/articles/360000313622

I hope this helps.

Hi Yuzo-san,

I have tried using PUT rest api, went I execute the code it will update/overwrite the subtable. What I want is to insert the subtable data from App A to subtable App B that has the same Product Code

Lets say, Example.

App A

Product Code: 20-00001

Subtable Content

Quantity:

2000

 

App B

Product Code: 20-00001

Subtable Content

Quantity:

1000

 

Result:

App B

Product Code: 20-00001

Subtable Content

Quantity:

2000

1000

here is my code.

(function() {

    “use strict”;

    

            kintone.events.on([‘app.record.create.submit’,‘app.record.edit.submit’], function (event) {

                var record = event.record;

                var prodcodesales = record[‘productcode’].value;

                var Table

                a

                            

                    var body = {

                        “app”: 375,

                        “records”: [{

                        “updateKey”: {

                            “field”: “prod_code”,

                                “value”: prodcodesales.toString()

                        },

                        “record”: {

                            “TableTestB”: {

                                “value”: [

                                    {

                                        “value”:{

                                            “NumberB”:{

                                                “value”: 4000

                                            }

                                        }

                                    }

                                ]

                            }

                        }

                    }]

                }

                kintone.api(kintone.api.url(’/k/v1/records’, true), ‘PUT’, body, function(resp) {

                    // success

                    console.log(resp);

                }, function(error) {

                    // error

                    console.log(error);

                });

                

        });

    }());

 

Thank you so much for helping.