Category Archives: Kintone

フィールド更新時に別のフィールドを更新(コンストラクタ利用)

var Field = function(field_id) {
  this.field_id = field_id;

  this.associate = function(event) {
    console.log("change")
    var field_id = 'フィールド2'
    var current_value = event.record[this.field_id].value
    value = current_value + "yes"
    event = this.updateField(event, field_id, value)
    return event
  }

  this.updateField = function(event, field_id, value) {
    var record = event.record;
    record[field_id].value = value;
    return event;
  };

  var _this = this
  kintone.events.on('app.record.edit.change.'+this.field_id, function(event) {
    event = _this.associate(event)
    return event
  })

}

var editEvents = ['app.record.create.show', 'app.record.edit.show'];
kintone.events.on(editEvents, function(event) {
  var field_id = 'フィールド1'
  var field = new Field(field_id)
  return event
});

フィールド更新時に別のフィールドを更新

var editEvents = ['app.record.create.show', 'app.record.edit.show'];
kintone.events.on(editEvents, function(event) {
  console.log("accessed to editpage");
  kintone.events.on('app.record.edit.change.フィールド1', function(event) {
    console.log("changed field1");
    updateField(event, "フィールド2", "yes");
    return event;
  });
});

var updateField = function(event, field, value) {
  var record = event.record;
  record[field].value = value;
  return event;
};