Update connection records

Comments

2 comments

  • Avatar
    Jeff Napolski

    id like an answer too

  • Avatar
    undefined undefined

    found the solution (see bellow) with the help of some good people in these forums . The secret sauce is in the 

    cust_conn

    variable :)

    $(document).on('knack-record-create.view_125', function(event, view, record) {

    Knack.showSpinner();

    var KnackAppID = "xxxx"
    var KnackAPIKey = "xxxx"

    $.ajax({url: 'https://api.knackhq.com/v1/objects/object_1/records', type: "GET",
    headers: {"X-Knack-Application-Id": KnackAppID, "X-Knack-REST-API-Key":KnackAPIKey},
    success: function(data) { //alert('Records Retrieved!' + data.total_records);

    for (var i = 0; i < data.total_records; i++) {//alert(data.records[i].field_1);
    var cust_conn = [data.records[i].id]
    var newdata = {
    field_99: i + 1, //Customer Group Number
    field_104: cust_conn, //Customer Name
    field_102: data.records[i].field_25_raw, //License Number
    field_97: record.field_97, //Customer Group Name
    field_101: record.field_101_raw[0].id, //Segmentation
    field_109: data.records[i].field_103_raw, //Customer segta ID
    field_110: data.records[i].field_4_raw, //Specialties
    field_111: data.records[i].field_24_raw, //Territories
    field_112: data.records[i].field_27_raw, //Organisations
    field_113: data.records[i].field_28_raw //Products

    }

    $.ajax({
    url: "https://api.knackhq.com/v1/objects/object_15/records/",
    type: "POST",
    headers: {'X-Knack-Application-Id': 'xxx', 'X-Knack-REST-API-Key':'xxx'},
    data: newdata,
    //success: function(response) {alert('Records Added!');}
    });
    }
    Knack.hideSpinner();
    }
    });
    });

     

Please sign in to leave a comment.