
Update Related Records Using JavaScript API
Hello,
I'm trying to fill in the "Related Records" field with results from my own query using the JavaScript API. I'm using the below code to fetch the data. Since this function returns an array of records, can't I just load them in the related records field by using its field code? Is this even possible?
var rec = event.record;
var customer = rec.Customer.value;
var start_period = rec.Start_Period.value;
var end_period = rec.End_Period.value;
var query = 'Customer="'+ customer +'" and Start_TIme >= "'+ start_period +'" and Start_TIme <= "'+ end_period +'"';
var getAllSummaryDetailsWithQuery = function() {
var body = {
app: HOURS_LOG_APP_ID,
query: query
};
return kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body).then(function(resp) {
if ( resp.records.length === 0 ) {
alert("No data was returned.");
return event;
}
return resp.records;
}).catch(function(error){
console.log("Request couldn't complete.");
});
};
2 comments
Hi Christopher,
It is not possible to use the API to update the information in the related record based on the result retrieved by GET.
The desired process cannot be achieved using the standard fields of kintone, including related records, so you need to create your related records.
Below is a sample code based on two apps, the class management app and the student management app.
(the code is applied to the class management app)
Class management app:
Field Type Field Name Field Code Remark
Record Number Class number class_no -
Text Class code class_code -
Text Class name class_name -
Space - student_list Space for table display
Student management App:
Type of field Field name Field code Remark
Record number Student number student_no -
Text Student code student_code -
Text Name student_name -
Lookup Class code class_code Table
Text Class name class_name Table
※Replace the '104' part of '<a href="/k/104/show#record=' with the app ID of the student management app.
Could you try and see if this accomplishes the desired process?
Hopefully, it helps.
Hi Sean!
Thank you so much for all your help! That worked perfectly. I wasn't sure how to create the custom HTML table so now I can using this method in future projects!
Much appreciated,
Chris Krieg