Writing data to records called by a saved search

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Writing data to records called by a saved search

Viewing 1 reply thread
  • Author
    Posts
  • March 7, 2024 at 9:58 AM #50606

    Victor Warner
    Participant

    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.
    March 7, 2024 at 2:20 PM #50610

    Daniel Leu
    Participant

    You’re missing document.saveAllChanges(); after you set the new field values.

Viewing 1 reply thread

You must be logged in to reply to this topic.