I am trying to learn to use loops in JavaScript combined with a saved search. I have been able to create a script that can obtain the required data from fields in records found by a saved search. However, I cannot write some data to a field for the records found by a saved search.
Could I have some help in identifying what is wrong or what needs adding. The sample database is attached.
// Fields
var date_id = 'fld-93ed9225fc674e7c840266726e160538';
var first_name_id = 'fld-edfdac34b4de4df79e5aced3c3ddc9be';
var completed_id = 'fld-6a9df78c9df744e292f47e11077d3d6d';
var client_name_id = 'fld-ec4fb9b85cb54d52813a9cd69c08198f';
// Push variable
var txt = [];
// Getting saved search
var saved_search = form.getSearchNamed('Completed');
// get the records for the saved search
var dupes_search = saved_search.getRecords();
// Looping through the records for the saved search
for (var index = 0, count = dupes_search.length; index < count; index++){
var dupes_search_details = dupes_search[index];
// getting the contents of fields
var completed = dupes_search_details.getFieldValue(completed_id);
var client_name = dupes_search_details.getFieldValue(client_name_id);
// writing data to fields
dupes_search_details.setFieldValue(first_name_id, "Johnny");
//dupes_search_details.setFieldValue(date_id, "2024-03-06");
// putting data from fields together
txt.push((index+1) + ". " + client_name + " = " + completed + ", and the count of records found by saved search: " + count + "\n");
}
txt.join();
console.log(txt);
Attachments:
You must be
logged in to view attached files.
You’re missing document.saveAllChanges();
after you set the new field values.