Here is a script that OpenGPT has suggested that partially works:
$(document).on(‘knack-view-render.view_235’, function(event, view) {
$(document).on('click', '.SFRButton', function(e) {
var $tableRow = $(this).closest('tr');
// Extract value of 'field_49' from the current row.
var fieldValue49 = $tableRow.find('.field_49').text().trim();
console.log("Captured field 49 value:", fieldValue49);
var objectID = 'object_8';
var headers = {
"X-Knack-Application-Id": "XXXXXXXXXXXXX", // Replace with your App ID
"X-Knack-REST-API-Key": "XXXXXXXXXXXXXX" // Replace with your API Key
};
// First, search for the record in 'object_8' that matches 'field_49' value
$.ajax({
url: 'https://api.knack.com/v1/objects/' + objectID + '/records',
method: 'GET',
headers: headers,
data: {
'filters': [{
'field':'field_49',
'operator':'is',
'value':fieldValue49
}]
},
success: function(response) {
console.log("API response:", response);
if (response.records && response.records.length > 0) {
var recordID = response.records[0].id;
// Now, update 'field_407' of the found record
$.ajax({
url: 'https://api.knack.com/v1/objects/' + objectID + '/records/' + recordID,
method: 'PUT',
headers: headers,
data: {
'field_407': "YES"
},
success: function(updateResponse) {
console.log("Field updated successfully!");
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Error updating field:", textStatus, errorThrown);
}
});
} else {
console.error("No matching record found for field_49 value:", fieldValue49);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Error searching for record:", textStatus, errorThrown);
}
});
});
});
As you can see, it’s capturing field 49 and trying to match in the table with field 49 data captured and when is found, updates field 407 to “YES”. According to the console log, it’s capturing field 49, but not updating field 407 to “YES”. Just a fyi, field 49, the link field (SFRButton) and field 407 are in the same table and row.
Any help with this is appreciated…