Adding data to fields in currently selected record

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Adding data to fields in currently selected record

Viewing 2 reply threads
  • Author
    Posts
  • February 26, 2024 at 5:27 AM #50556

    Victor Warner
    Participant

    I have the following script which writes data from a .csv file to several fields. It does so by adding a new record and then writing the data to the fields. I would like to know how to do so to the currently selected record.

    Any help would be gratefully received.

    // this imports the Papa Parse script
    
    form.runScriptNamed('PapaParse');
    
    // replace with your field ID's
    
    var date_of_invoice_id = 'fld-1b800a91fac14b329ef47d23c7cdacb0';
    var date_paid_id = 'fld-60fa17dec2a24d9588ce4aafa3dccd5c';
    var date_of_receipt_id = 'fld-9ed8f17873a642b4a2ee58ff24eba421';
    var method_of_payment_id = 'fld-15b719109ab64053a5c46427622f81f5';
    var payment_notes_id = 'fld-3a22501b3096443f8f92c6cf6c7e2de5';
    
    function Import_Entries() {
    //let filename = "file:///Users/victor/vwdata/data/Notary/client database/not in use/FileMaker/notary/vPaymentDetails.csv";
    let filename = "file:///Users/victor/Library/Mobile Documents/com~apple~CloudDocs/filedtoday/vPaymentDetails.csv";
    
     
    
    let csvFile = Utils.getTextFromUrl(filename);
    
    if (!csvFile) {
    console.log("No CSV file?");
    return
    }
    
    var output = Papa.parse(csvFile);
    
    // abort if there are any errors and log to console.
    if (output.errors.length > 0) {
    console.log(errors.join("\n"));
    return;
    }
    
    // read each line
    for (let line of output.data) {
    var newRecord = form.addNewRecord();
    newRecord.setFieldValues({
    [date_of_invoice_id]: line[0],
    [date_paid_id]: line[1],
    [date_of_receipt_id]: line[2],
    [method_of_payment_id]: line[3],
    [payment_notes_id]: line[4],
    });
    //var job_completed_id = 'fld-ba0622aac1ea42ff9e5e9272c4314fa7';
    
    //record.setFieldValue(job_completed_id,"Yes");
    
    document.saveAllChanges();
    }
    }
    
    // Import entries to form "Who" from filename "Whom.csv"
    Import_Entries("Notarial Act", "vPaymentDetails.csv");
    
    • This topic was modified 9 months, 4 weeks ago by Victor Warner.
    February 26, 2024 at 11:34 AM #50558

    Daniel Leu
    Participant

    To refer to the current record just use record. To set a value, it would be record.setFieldValues();.

     

    February 27, 2024 at 5:21 PM #50565

    Victor Warner
    Participant

    Daniel,

    Thank you for the information.

    Victor

Viewing 2 reply threads

You must be logged in to reply to this topic.