Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
October 8, 2021 at 11:20 AM #45424
In reply to: Script for find and modify records
Fernando DS
ParticipantI send both scripts. They are the same, just change the fieldid and the words to be changed. Where is the mistake?
Attachments:
You must be logged in to view attached files.October 8, 2021 at 9:58 AM #45422In reply to: Using Javascript to import csv files
Victor Warner
ParticipantSam,
Thank you very much for the script.
On the first run it worked – it imported the .csv file.
On subsequent runs – nothing was imported – and no error was generated.
The script as I used:
// this imports the Papa Parse script form.runScriptNamed('PapaParse'); // replace with your field ID's var first_name_id = 'fld-068c60aaec5047ea93f46988251ae938'; var last_name_id = 'fld-4155c0ec104e4448af17f2776880d205'; var email_id = 'fld-6a9e9e828e294e2ca694e751c7f3faf9'; var date_id = 'fld-9c739c301f614a7c8b21eb427059430e'; function Import_Entries() { let filename = "file:///Users/victor/Desktop/Whom.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({ [first_name_id]: line[0], [last_name_id]: line[1], [email_id]: line[2], [date_id]: line[3], }); document.saveAllChanges(); } }The .csv file contains one line:
Simon,Adams,Noone@AtHome.com,01/02/1888
I tried changing the data but that made no difference.
I attach the database in case there is something in that which shows what the issue is.
Attachments:
You must be logged in to view attached files.October 8, 2021 at 9:13 AM #45421In reply to: Script for find and modify records
Fernando DS
ParticipantI will look for that video. In the meantime i have been doing some tryings with the script. I want search in any other field. I though it be easy. But not at all. I have changed the fileid, and the words to be changed. The rest of the script exact the same. But I have errors. How is possible?.
October 7, 2021 at 5:46 PM #45419In reply to: Newbie Questions
Sam Moffatt
ParticipantThe first could possibly be achievable using a number of script fields to calculate the values you’re after and then you could display them. It’d be a weird use case because it’d be a form full of script fields that calculate values in other forms/searches but conceivably that could work. It’d be a non-trivial amount of work to setup.
October 7, 2021 at 5:41 PM #45418In reply to: Using Javascript to import csv files
Sam Moffatt
ParticipantSo the link in the original post has an example of
Utils.getTextFromUrl, the same sort of instructions apply.For a CSV parser, I just tried Papa Parse and it worked fine. I went to their GitHub repo and copied their uncompressed Javascript code into a new form script called “PapaParse”. I did the following quick test and it worked properly:
form.runScriptNamed('PapaParse'); function Csv_Parse_Test() { // Replace with your own code var hello_world = '"Hello, World!",Test,123'; var output = Papa.parse(hello_world); console.log(JSON.stringify(output, null, '\t')); } Csv_Parse_Test();Outputted the following:
7/10/21, 5:22:19 pm / Script Examples / CSV Parse Test { "data": [ [ "Hello, World!", "Test", "123" ] ], "errors": [], "meta": { "delimiter": ",", "linebreak": "\n", "aborted": false, "truncated": false, "cursor": 24 } }This seems to be correct interpretation of the input. So let’s put that together with the earlier post:
// this imports the Papa Parse script form.runScriptNamed('PapaParse'); // replace with your field ID's var title_id = 'fld-4e8e68e2979643be8417c3469015abff'; var description_id = 'fld-429934cd6ae646b1ac1cf5ad659cb926'; var url_id = 'fld-b46c858779094c9d906f2ce5e5c4a028'; var upload_date_id = 'fld-fc1f8537415c4d6cabb8c0784b64f2a6'; var thumbnail_url_id = 'fld-12b4e040711b4afea624c7c049fdd7ce'; function Import_Entries() { let filename = "file:///Users/yourusernamehere/Documents/input.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({ [title_id]: line[0], [description_id]: line[1], [url_id]: line[2], [upload_date_id]: line[3], [thumbnail_url_id]: line[4] }); document.saveAllChanges(); } } Import_Entries();First thing we do is pull in the Papa Parse script. Then we have the field ID’s for our fields that we’re going to use. We could put this anywhere, I like it being in global scope since they’re immutable anyway.
We enter the function and define the path to the file. If you don’t know what this is, drag the file from Finder into the script editor and it’ll put the full path in for you. Make sure this folder is the same one you’ve given access to in the Script Folder Access in the preferences for this document. The next line imports that file for you.
We then check to see if we got anything from the CSV file, if we didn’t we log an error and return flow control. We then hand the contents of the file to
Papa.parseand if it has any errors we log them and return as well.We then read each line of the data to process it, create a new record, map the field order in the CSV to our Tap Forms field ID’s and then save the changes.
You might get a performance boost moving the
document.saveAllChanges()line but there are quirks around creating new records that cause me to leave the save in the loop not outside.I’ve not tested it but something like that should work.
October 7, 2021 at 1:01 PM #45415In reply to: Script for find and modify records
Sam Moffatt
ParticipantYou probably just need to delete line one entirely (the
function Buscar_Y_Modificarone) . That looks like the old placeholder which you don’t need since you’ve got a function (Replace_Metal). Assuming that’s the full script then nothing else jumps out at me as wrong.If that works, you could also change
Replace_MetalwithBuscar_Y_Modificaron thefunctionline and also at the bottom of the script (e.g. changeReplace_Metal();withBuscar_Y_Modificar();).October 7, 2021 at 11:47 AM #45412In reply to: Script for find and modify records
Fernando DS
ParticipantThe script photo is going on now.
Attachments:
You must be logged in to view attached files.October 7, 2021 at 11:43 AM #45410In reply to: Script for find and modify records
Fernando DS
ParticipantHi Daniel, thank you for your support. I have done it and I sent the script as it is now. But there is an error, that I also sent.
Attachments:
You must be logged in to view attached files.October 7, 2021 at 8:08 AM #45407In reply to: Script for find and modify records
Daniel Leu
ParticipantPlease see Sam’s answer to fix your error: https://www.tapforms.com/forums/topic/script-for-find-and-modify-records/#post-45401
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksOctober 7, 2021 at 5:51 AM #45406In reply to: Using Javascript to import csv files
Victor Warner
ParticipantThank you for the responses.
I would be grateful for a simple illustration how to use
Utils.getTextFromUrlwith a CSV file stored on a computer, how to parse the CSV, and then save the elements to different fields in a form.Since I can only do the most basic things with JavaScript I am not sure how even to begin a script such as this.
October 6, 2021 at 11:02 PM #45399In reply to: Script for find and modify records
Fernando DS
ParticipantOk. Thank you everybody for your kind answers. This is what I have done in the script and the error that appears in the console.
Attachments:
You must be logged in to view attached files.October 6, 2021 at 5:11 PM #45396In reply to: Script for find and modify records
Daniel Leu
ParticipantHave a look at Sam’s videos such like this one: https://www.youtube.com/watch?v=xB1XZyBYNd4&ab_channel=pasamio. You will see the field id about 4 minutes into the video. He has many more on TapForms and scripting on his channel. It is worthwhile to check them out.
T.L. Ford wrote a scripting 101 as well: http://www.cattail.nu/tap_forms/tap_forms_scripting_101/index_tap_forms_interface.html
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksOctober 6, 2021 at 5:05 PM #45395In reply to: Script for find and modify records
Daniel Leu
ParticipantThe easiest way to get the field ID is to double click on the field name in the script editor. Or you can click on the field name and the select the “ID” field.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksOctober 6, 2021 at 3:09 PM #45393In reply to: Script for find and modify records
Fernando DS
ParticipantOk. I understand the curly and straight quotes. But I can’t find the field id. Neither the script editor, nor beneath the field lost on the property panel. Sorry, I must be very incompetent. I’m using an iphone, I have not got a Mac. Perhaps the problem is this? Thank you very much for your time and patience.
October 6, 2021 at 12:47 PM #45390In reply to: Script for find and modify records
Brendan
Keymastervar fieldId = ‘fld-fieldid’;Because first of all, you’re using curly quotes. They need to be straight quotes.
Plus Tap Forms generates random field IDs.
fld-fieldidwill never be the field ID that Tap Forms generates. That was just a sample value Sam put in there. You need to change it to be your actual Field ID which you can get from the Script Editor or just beneath the Fields list on the field property panel. -
AuthorSearch Results