Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Error messages on import via Javascript
- This topic has 4 replies, 3 voices, and was last updated 3 years ago by Sam Moffatt.
-
AuthorPosts
-
December 6, 2021 at 5:00 AM #45963
Victor WarnerParticipantBackground
1. I am importing several csv files into different forms via a form script
2. Sam and Brendan have provided the code to achieve what is needed (see https://www.tapforms.com/forums/topic/using-javascript-to-import-csv-files/ andhttps://www.tapforms.com/forums/topic/importing-data-via-javascript-not-working-with-dates/ )
3. The form script exists in a form named “Client Contact Details”). Several forms are linked to to this (via Link to Form). (Client Contacts Details linked to forms :”Passport”, “Other ID” and “Notarial Act”.)
4.The script to import adds separate code to import each csv file as mentioned in Sam’s post (https://www.tapforms.com/forums/topic/using-javascript-to-import-csv-files/#post-45439):
>” The easiest way would be to copy the function and replace the mappings. So instead of Import_Entries() and Import_Whom() and you just change the file name, remap the field mapping and instead of form.addNewRecord() you do document.getFormNamed(“Other Form”).addNewRecord(). That means a bunch of duplicated code but it will work.”
5. Now I am adding the code to import into a further form (“Notarised Documents”) which is not linked to the Client Contacts Folder. The script works properly – the data is imported without issue but generates a number of errors in the console log.
The code:
// this imports the Papa Parse script form.runScriptNamed('PapaParse'); // replace with your field ID's let dup_field = "X"; // Notarised documents var type_of_document_id = 'fld-d97eadb774254768bc874a8d9c39bb55'; var country_id = 'fld-04fc73a0c470486aa95dde105f8c3bd7'; var date_of_event_id = 'fld-01e1904f176e4f5589e4acb2935b77d9'; var place_of_event_id = 'fld-44e431c6ad5744378dc396d30736d0b0'; var date_notarised_id = 'fld-369e7b99cd0748f6a15a04cf500ba23f'; var place_notarial_certificate_signed_id = 'fld-8aa2fb1ba19e48afab5f77bb9bca0742'; var number_of_pages_id = 'fld-b6882198382f4b368dccfa874e69a563'; var for_duplication_id = 'fld-03f0a59ce814421ba5107faa956c16c6'; let dup_notarised_document = for_duplication_id; // Function to split date and ressemble (to be called later) function parseDate(dateString) { if (!dateString) { return undefined; } let pieces = dateString.split("/"); return new Date(pieces[2], pieces[1] - 1, pieces[0]); } // Import notarial act function Import_NotarisedDocuments() { let filename = "file:///Users/victor/Library/Mobile Documents/com~apple~CloudDocs/filedtoday/personal/Tap forms import test/notariseddocuments.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) { // date of event parsing let date_of_event_id_string = line[2]; let date_of_event = parseDate(date_of_event_id_string); // date certificate signed parsing let date_notarised_id_string = line[4]; let notarised_date = parseDate(date_notarised_id_string); var newRecord = document.getFormNamed("Notarised documents").addNewRecord(); newRecord.setFieldValues({ [type_of_document_id]: line[0], [country_id]: line[1], [date_of_event_id]: date_of_event, [place_of_event_id]: line[3], [date_notarised_id]: notarised_date, [place_notarial_certificate_signed_id]: line[5], [number_of_pages_id]: line[6], [dup_notarised_document]: dup_field, }); document.saveAllChanges(); } } Import_NotarisedDocuments();
(This is the stand alone version – but the issue is the same whether combined with the code to import for the other form or as standalone).
The errors which are generated are:
undefined undefined stamp How provided wording: TypeError: undefined is not an object (evaluating 'client_name.toUpperCase'), line:(null) undefined undefined stamp undefined undefined stamp
Query: Is this an issue which I should not worry about. Or is there anything I need to add so that the errors do not appear?
December 6, 2021 at 5:29 PM #45968
Sam MoffattParticipantAre you sure that error isn’t generated by a field script? I don’t see anything that would cause that error in the script you pasted but it’s possible the messages actually come from a field script that is executing when the values are updated.
December 7, 2021 at 12:58 AM #45969
Sam MoffattParticipantAs an aside if it is in a field script, you might be ok with it erroring out like you see there but you can also likely detect when it’s empty and replace it with an empty string:
if (!client_name) { client_name = ""; }
That should fix the
toUpperCase
error from occurring. Theundefined
could be other log messages that are occurring similarly withstamp
. The down side ofconsole.log
is that it all gets thrown in together.December 7, 2021 at 1:15 AM #45970
BrendanKeymasterI suppose a Console Log window that splits the output from the console log would be useful, like on the script editor.
December 7, 2021 at 6:07 PM #45981
Sam MoffattParticipantI could see a debug mode option to prefix the lines with the script that the log message was coming from, I struggle with that with errors from time to time figuring out which library actually choked. I’m not entirely sure that’s actually possible due to how I understand the JSC integration works because it’s not obvious the context you’re calling from includes the layers of parser or not.
-
AuthorPosts
You must be logged in to reply to this topic.