How to get and pass a field value from one Kintone App to another?

Question / Problem

How do I get the value of a Kintone App’s field and pass it to another Kintone App using the GET REST API?

Thank you in advance

Current Situation

First, I want to fetch the value of the Company List App’s Street Address field value (Ex/ Groove Street).

Then, I want to pass the text string to Sales Deals App’s Street Address field.

Company List App

Value of Street Address:

Sales Deals App

I want to pass the “Groove street” value to this Kintone App:

Code / Attempts

Here is my GET REST API call:

### kintone REST API Requests - App Records
@domain = INSERT_SUBDOMAIN.kintone.com
@appId = INSERT_APP_ID
@apiToken1 = INSERT_API_TOKEN_1
@apiToken2 = INSERT_API_TOKEN_2
@userCode = Administrator

### GET/records
GET https://{{domain}}/k/v1/records.json?app={{appId}}
X-Cybozu-API-Token: {{apiToken1}}

### POST/records
POST https://{{domain}}/k/v1/records.json
X-Cybozu-API-Token: {{apiToken1}}, {{apiToken2}}
Content-Type: application/json

{
  "app": {{appId}},
  "records": [
    {
      "Company_Name_Search": {
        "value": "Kintone"
      },
      "Deal_Name": {
        "value": "Kintone app creation"
      },
      "Rep": {
        "value": [{"code": "{{userCode}}"}]
      }
    },
    {
      "Company_Name_Search": {
        "value": "Cybozu"
      },
      "Deal_Name": {
        "value": "Kintone JavaScript customization"
      },
      "Rep": {
        "value": [{"code": "{{userCode}}"}]
      }
    }
  ]
}

### DELETE/records
DELETE https://{{domain}}/k/v1/records.json?app={{appId}}&ids[0]=1
X-Cybozu-API-Token: {{apiToken1}}

### POST/file
POST https://{{domain}}/k/v1/file.json
X-Cybozu-API-Token: {{apiToken1}}
Content-Type: multipart/form-data; boundary=----20111107kintone20111107cybozucom

------20111107kintone20111107cybozucom
Content-Disposition: form-data; name="file"; filename="kintone.jpg"
Content-Type: image/jpeg

< ./kintone.jpg
------20111107kintone20111107cybozucom--

### PUT/record for updating file
PUT https://{{domain}}/k/v1/record.json
X-Cybozu-API-Token: {{apiToken1}}
Content-Type: application/json

{
    "app": {{appId}},
    "id": "1",
    "record": {
      "Attachment": {
        "value": [{
          "fileKey": "your_file_key"
        }]
      }
    }
}

Desired outcome / Expected Behavior

I want to copy the street address value:

To this street address field code:

Referenced Resources

Hello @Jayron_Rosel ,

Thank you for re-posting with additional information, and sorry for my delayed response.

What are the field codes for the following fields?

  • Company List App > Street Address field
  • Sales Deals App’s Street Address field

An easy way to get the field codes is to run the following script in the browser console:

:zap: This will return the field codes and fields’ values for Record 1.

const body = {
  'app': kintone.app.getId(),
  'id': 1
};

kintone.api(kintone.api.url('/k/v1/record', true), 'GET', body, function(resp) {
  // success
  console.log(resp.record);
}, function(error) {
  // error
  console.log(error);
});

Here are my field code sir:

  • Company List App > Street Address field = Street_Address
  • Sales Deals App’s > Street Address field = street_address

and additional, where do I put that code sir?

thank you

1 Like

Hello @Jayron_Rosel

I assume you are using Company Name as a key to distinguish which record of getting data from. It depends on your situation, but this is an example script that could get and pass a field value from one app to another when a button is pressed.

(function() {
  "use strict";

  var AppId = *App ID you are retrieving data from*;

  kintone.events.on(['app.record.edit.show', 'app.record.index.edit.show'], function(event) {
    // Placing a button on a space field
    var btn = document.createElement('button');
    btn.id = 'my_space_field_button';
    btn.innerHTML = 'Space Button';
    btn.onclick = function () {
      kintone.api(
        kintone.api.url('/k/v1/record', true),
        'GET', {
          app: AppId,
          id: event.record['CompanyName'].value
        },
        function(resp) {
          var record = kintone.app.record.get();
          record['Street_Address'].value = resp.record['street_address'].value;
          kintone.app.record.set(record);
        }
      );
    }
    kintone.app.record.getSpaceElement('my_space_field').appendChild(btn);
  });
})();

Please refer to the Ref. for more examples.
For your information, it depends on your situation, but you can use a lookup field to copy data from another app.

Ref.: