Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 15, 2020 at 3:19 PM #42607
In reply to: conditional copy values from on table to another
Brendan
KeymasterHello Winfried,
The Table field is only available to the form that you put it on.
If what you need is a Shopping List form that links to ingredients, then you’ll have to create a separate Ingredients form that you link to from your Shopping List form AND from your Recipes form.
Or alternatively, skip the Shopping List form and just have your Recipes form and an Ingredients form. Then just visit the Ingredients form whenever you want to go shopping. Put your Checkmark field as your first field in the form and when you do that, on iOS, you’ll see a checkmark button to the left of the ingredient name. Tapping on it will check it on or off. Also, if you sort by the Checkmark field then you could have all the unchecked items at the top and all the checked items at the bottom. So as soon as you’ve bought an ingredient, tap on the checkmark and it will move down to the list of checked items.
But then you’d want to have a way of resetting all of the checkmark fields back to unchecked before you go on your next shopping excursion. The only way to do this is to either manually uncheck the items you want to buy, or write a Form Script that un-checks them all for you in one go.
Thanks!
Brendan
November 15, 2020 at 11:27 AM #42602Sam Moffatt
ParticipantA few more questions if I may. I have tried to figure things out by watching some of Sam’s videos etc., but I am a little stuck.
Curious for feedback, were any of them helpful? What was not helpful and what would improve it? What was helpful and how was it helpful? I had thought about doing another simple intro one on the next few snippets which includes functions but haven’t done it. I tried another video on some other topics but wasn’t happy with how it turned out.
So first, from my reading it looks like I need to use a “Form Level Script” as opposed to a “Field Level Script” as I am updating existing records.
I think my rule of thumb is that field scripts are meant to act on the contents of the record as those contents change whilst form scripts are more one off or bulk action changes. You can use them somewhat interchangeably and the question is do you want this thing to run all of the time or is it something you want to control when it runs?
I only have two forms, my main database and the cvs data I want to input. Is it correct that I must place the Form Level Script in my main database and not in the cvs form? (That seems to be the only way I can get the correct fld-hash numbers that I need into the script).
While it might not be intuitive you can access any form and any field from scripts (fields or forms) in any form within a document. The editor won’t show you the fields that aren’t directly linked to the form that you’re in but you can use the editor to go to other forms and get their field ID’s. You can also get the field ID from below the description box in the field editor UI.
You can use the code button to wrap your code with backticks (e.g. `code here`) to make it a little easier to read (also ran it through a formatter since the post didn’t have any indentation):
function addKeyword(rec, kw_id, kw) { var keywords = rec.getFieldValue(kw_id); if (keywords == undefined || keywords == "") { rec.setFieldValue(kw_id, kw); } else { rec.setFieldValue(kw_id, keywords + ',' + kw); } } function Update_Records() { var csvForm = document.getFormNamed("csv"); var ContractsForm = document.getFormNamed("Contracts"); // Contracts var pdffilepath_7_id = 'fld-3ea77ccc18604174b722ece105965c44'; var license_category_id = 'fld-d63ab1856e554efebe62b9f1826c388d'; var license_subcategory_id = 'fld-f0c47c7e6ad244fe955e2c24cb448590'; var agreement_keywords_id = 'fld-a2126cbe512646e9ba144fb5a90b06dc'; // get csv field Ids var pdffilepath_7 = cvsForm.getFieldNamed('PDF').getId(); var license_category = cvsForm.getFieldNamed('Category').getId(); var license_subcategory = cvsForm.getFieldNamed('Subcategory').getId(); var agreement_keywords = cvsForm.getFieldNamed('Keyword').getId(); // Loop over all csv entries // So this tells my Contracts database to look at the cvs form? for (entry of cvsForm.getRecords()) { // get pdf file name // is it looking for another fld-hash here? var pdfName = entry.getFieldValue(csvPdf_id); // replace spaces with underscores pdfName = pdfName.replace('/ /g', '_'); console.log("Processing: " + pdfName); // Loop over all LICENSEdb records for (Contracts of Contracts.getRecords()) { // this assumes that there is only one PDF per Contract // where have I defined (pdf_id) before? Do I need to ? var filename = Contract.getFieldValue(pdf_id)[0].filename; if (pdfName == filename) { console.log("Found match: " + filename); // Update Contracts record addsubcategory(Contracts, subcategory_id, entry.getFieldValue(csvKeyword_id)); // Update Contracts record addKeyword(Contracts, keyword_id, entry.getFieldValue(csvSubcategory_id)); // Set category Contracts.setFieldValue(category_id, entry.getFieldValue(csvCategory_id)) break; } } } document.saveAllChanges(); return 'done'; } Update_Records();First thing I noticed when I put it through a formatter was that there seemed to be a missing bracket, I’ve added an extra one before the
document.saveAllChanges()line and everything balanced out. I used Visual Studio Code to reformat it but I also found an online JavaScript beautifier as well.Next, much of the script makes sense to me, and other parts seem somewhat circular. Could you look what I have done and see where I messed up? …because I think I did a good job on that : )
I need the script to look up each record that aligns with the PDF file name in the cvs file, and then update the records in the main database form called “Contracts”
Now I see you added an extra call:
addsubcategory (Contracts, subcategory_id, entry.getFieldValue(csvKeyword_id));What this change is doing is trying to call a function here called
addsubcategorybut that function doesn’t exist. I think you’re trying to copy theaddKeywordline for a new field and if you look at the very top of the script there is afunction addKeywordwhich defines or creates the function. If what you’re trying to do is create a comma separated list of sub categories but in a different field, then I don’t think you need to do a new function, I think you can just calladdKeywordwith the sub category field ID:addKeyword (Contracts, subcategory_id, entry.getFieldValue(csvKeyword_id));Try fixing the curly braces and changing
addsubcategoryover toaddkeywordas above and see if that gets you a little closer.November 15, 2020 at 7:09 AM #42591In reply to: Updated Script Manager
Max Heart
ParticipantSam, you are amazing. Just watched your video on the Script Manager. Thank you so much for all your work.
Best, MaxNovember 14, 2020 at 5:21 PM #42586Brent S
ParticipantHi Daniel,
A few more questions if I may. I have tried to figure things out by watching some of Sam’s videos etc., but I am a little stuck.
So first, from my reading it looks like I need to use a “Form Level Script” as opposed to a “Field Level Script” as I am updating existing records.
I only have two forms, my main database and the cvs data I want to input. Is it correct that I must place the Form Level Script in my main database and not in the cvs form? (That seems to be the only way I can get the correct fld-hash numbers that I need into the script).
Next, much of the script makes sense to me, and other parts seem somewhat circular. Could you look what I have done and see where I messed up? …because I think I did a good job on that : )
I need the script to look up each record that aligns with the PDF file name in the cvs file, and then update the records in the main database form called “Contracts”
I have attached a few screen shots in case that helps with context.
Thanks again.
Brent——————-
function addKeyword(rec, kw_id, kw) {
var keywords = rec.getFieldValue(kw_id);
if (keywords == undefined || keywords == “”){
rec.setFieldValue(kw_id, kw);
} else {
rec.setFieldValue(kw_id, keywords + ‘,’ + kw);
}
}function Update_Records() {
var csvForm = document.getFormNamed(“csv”);
var ContractsForm = document.getFormNamed(“Contracts”);// Contracts
var pdffilepath_7_id = ‘fld-3ea77ccc18604174b722ece105965c44’;
var license_category_id = ‘fld-d63ab1856e554efebe62b9f1826c388d’;
var license_subcategory_id = ‘fld-f0c47c7e6ad244fe955e2c24cb448590’;
var agreement_keywords_id = ‘fld-a2126cbe512646e9ba144fb5a90b06dc’;// get csv field Ids
var pdffilepath_7 = cvsForm.getFieldNamed(‘PDF’).getId();
var license_category = cvsForm.getFieldNamed(‘Category’).getId(); var license_subcategory = cvsForm.getFieldNamed(‘Subcategory’).getId();
var agreement_keywords = cvsForm.getFieldNamed(‘Keyword’).getId();// Loop over all csv entries
// So this tells my Contracts database to look at the cvs form?
for (entry of cvsForm.getRecords()){// get pdf file name
// is it looking for another fld-hash here?
var pdfName = entry.getFieldValue(csvPdf_id);// replace spaces with underscores
pdfName = pdfName.replace(‘/ /g’, ‘_’);
console.log(“Processing: ” + pdfName);// Loop over all LICENSEdb records
for (Contracts of Contracts.getRecords()){// this assumes that there is only one PDF per Contract
// where have I defined (pdf_id) before? Do I need to ?
var filename = Contract.getFieldValue(pdf_id)[0].filename;if (pdfName == filename){
console.log(“Found match: ” + filename);// Update Contracts record
addsubcategory (Contracts, subcategory_id, entry.getFieldValue(csvKeyword_id));// Update Contracts record
addKeyword(Contracts, keyword_id, entry.getFieldValue(csvSubcategory_id));// Set category
Contracts .setFieldValue(category_id, entry.getFieldValue(csvCategory_id))break;
}}
document.saveAllChanges();return ‘done’;
}Update_Records();
Attachments:
You must be logged in to view attached files.November 14, 2020 at 10:27 AM #42582In reply to: Service Report
Sam Moffatt
ParticipantI turned this into a video on using a link to form to create the link and scripts (both form and field) to copy the values.
November 13, 2020 at 8:20 PM #42577In reply to: Service Report
Sam Moffatt
ParticipantI think the link to form field is probably the way to do part of it but you also want to intentionally duplicate data which is where I’d leverage a script.
For your link to form, create it in the “address” form and link back to your “service report” form. If you create a 1:M, in the “service report” form it’ll give you the option to select only a single address. Downside as you’ve noted is that it’s a link and if you delete it, it’s gone. Additionally if you update it, the historic nature of the service address is gone (if you could avoid updating that’d be the best option but that is it’s own data modelling problem).
The next step would be to create a script that looks at the link to form field and copies the data out from it. There are a couple of hints on how to do it and you can do it either as a form script (explicit copy) or a field script might work (implicit copy). There are some trade offs each way though a form script is a little easier to get started with I feel.
November 11, 2020 at 8:56 PM #42566In reply to: Suggestions for working with Mailchimp API?
Sam Moffatt
ParticipantOne of the workarounds I have for this is to leverage the built-in Apache web server and PHP which then handles the connections. It also makes it a little easier to work and debug because I can develop outside of Tap Forms and when I’m done, hook into Tap Forms. It gives me a lot more flexibility in coding as well because I have an entire PHP ecosystem to leverage. This allows hybrid functionality. It only really works on my own network or computer (depending on how I’ve done the scripts) but if that fits your use case it’s a great way to be able to handle more functionality in making web requests.
November 11, 2020 at 10:18 AM #42564In reply to: Personel E-Mail
Daniel Leu
ParticipantYou can do this with scripts. I posted this a while a go https://www.tapforms.com/forums/topic/creating-emails-from-tapforms/
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 10, 2020 at 3:38 PM #42558In reply to: Barcode Generate & Scan..
musicskidder
ParticipantThanks Dan, I suppose I can print a sheet of labels and make an entry manually. The ease of juggling so many records would then be to scan the tapes and have a search bring up the record that matches.
I have been looking at Pasamio’s barcode script video. It is a beginning…
Thank you,
StanNovember 10, 2020 at 12:18 PM #42552In reply to: Suggestions for working with Mailchimp API?
Daniel Leu
ParticipantLooking at the API example:
curl -sS \ "https://${dc}.api.mailchimp.com/3.0/ping" \ --user "<code>anystring</code>:${apikey}"I don’t think Tap Forms can work with the Mailchimp API as user authentication is not supported with the current Tap Forms Javascript API :(
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 10, 2020 at 11:06 AM #42548Topic: Suggestions for working with Mailchimp API?
in forum Script TalkPaul Wirth
ParticipantHi folks,
I have a Tap Forms database where I track client info. Clients are also in my Mailchimp email list. I’d like to be able to have my Tap Forms database update itself with any changes (unsubscribes, new subscribers, email address changes, etc) on Mailchimp, and vice versa using their API.
If anyone’s done this already, or something similar, I’d be grateful for any pointers. I have a beginner-level acquaintance with javascript—mostly in the sense that I am sometimes able to tweak existing scripts to do what I want. I’m not at all familiar with working with an API, however.
Grateful for any help!
November 9, 2020 at 9:56 PM #42539Brent S
ParticipantThank you Daniel! This is great. I am glad to know this is possible. It is going to take me a little bit of time to figure out scripting, but you have given me a great start.
My database is actually not a recipe database. That was just a simple example to illustrate the problem I have which is a lot more complex. Your answer will help me generate a solution.
The documents (readable PDF’s) I am dealing with are unstructured contracts and each are about 30 pages long, and yes each has its own unique file name. I do have them all in HTML too, but I think that might be a bit much to have that much text in Tap Forms?
So, just circling back to the one part of the solution, where I have a pick list with four choices, in my example, “Breakfast, Lunch, Dinner, Dessert” your code is as follows:
// Set category
recipe.setFieldValue(category_id, entry.getFieldValue(csvCategory_id))If I understand you correctly, I would put the word “Dessert” as one of the entries in the CSV file under “Category” and then this will overwrite it in the Pick List?
Anyhow. Thanks again!
November 9, 2020 at 8:27 PM #42537Daniel Leu
ParticipantYou can import a csv file into a separate form and then use a script to process all records and update your reference records accordingly. Then you can assign values of meal choices accordingly and update your keywords field as well.
But this seems to be a rather tedious job if you want to update all 50k food recipes in your Tap Forms database this way. I would start with looking into software that converts your PDFs into text files. Then you can add the content of your text files into fields inside Tap Forms. These fields are searchable, which makes it much easier to categorize your recipes. But yeah, it might be a challenge to convert your PDFs, specially if they were scanned and the quality is poor.
But if you want to go the CSV route, I would create a spreadsheet with columns for
PDF,Category, andKeyword. Here is my example:function addKeyword(rec, kw_id, kw){ var keywords = rec.getFieldValue(kw_id); if (keywords == undefined || keywords == ""){ rec.setFieldValue(kw_id, kw); } else { rec.setFieldValue(kw_id, keywords + ',' + kw); } } function Update_Records() { var cvsForm = document.getFormNamed("csv"); var recipesForm = document.getFormNamed("Recipes"); // recipes var category_id = 'fld-9828d73d445a4746a8dba4c0dac89716'; var keyword_id = 'fld-073ee12d29174c2eb64f7cf91f5bb383'; var pdf_id = 'fld-e870153bd0a647c9823ca998c213d1fd'; // get csv field Ids var csvPdf_id = cvsForm.getFieldNamed('PDF').getId(); var csvCategory_id = cvsForm.getFieldNamed('Category').getId(); var csvKeyword_id = cvsForm.getFieldNamed('Keyword').getId(); // Loop over all csv entries for (entry of cvsForm.getRecords()){ // get pdf file name var pdfName = entry.getFieldValue(csvPdf_id); // replace spaces with underscores pdfName = pdfName.replace('/ /g', '_'); console.log("Processing: " + pdfName); // Loop over all recipes records for (recipe of recipesForm.getRecords()){ // this assumes that there is only one PDF per recipe! var filename = recipe.getFieldValue(pdf_id)[0].filename; if (pdfName == filename){ console.log("Found match: " + filename); // Update recipe record addKeyword(recipe, keyword_id, entry.getFieldValue(csvKeyword_id)); // Set category recipe.setFieldValue(category_id, entry.getFieldValue(csvCategory_id)) break; } } document.saveAllChanges(); } return 'done'; } Update_Records();The first row of my spreadsheet are the field labels:
PDF,Category,Keyword. They are used to create the field names when creating a new form calledcsvupon importing your csv. The script is part of yourRecipesform.This script assumes that the keywords are comma separated. Keywords are added to your record if new ones are found. The category field is overwritten!
In order for the script to work, you need to update
category_id,keyword_id, andpdf_idaccording to your recipes form.Hope this helps! Happy cooking!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 9, 2020 at 2:55 PM #42535Brent S
ParticipantHi Everyone. I am new to scripting, so want to see if this is possible. Imagine the following situation. You have 50,000 food recipes all in PDF form input into the Tap Forms Database, each PDF with a unique file name and in a field where it is a “File Attachment”. So, there are then 50,000 records in the db. Many fields have been added to the database, but are empty until you manually go in and populate them. Is it possible to use scripts to help populate the data?
For example, lets say outside TapForms you use Spotlight on the iMac to identify 60 PDF’s (recipes) that contained the words “Gummy Bear”. You make an Excel File (.csv) with those 60 unique file names. Can you now write a script that would reference those file names in a .csv file, find/look up the specific records in tapforms where those files are attached and then do two things:
a) choose a picklist field that already exists, and choose one of the presets. For example, if this was a list of meal choices like “Breakfast, Lunch, Dinner, Dessert” the script would make it choose “Dessert” for each of those 60 records, but not any other records in the database
b) If you had a textfile field named KEYWORDS then have it add the term “Gummy Bear” to the list of keywords again just for those 60 records
If this is possible then I can see how scripting could help me and others categorize a very large database that would take a very long time to categorize manually. Any direction on what a script might look like would be extremely appreciated.
Thanks,
BrentNovember 8, 2020 at 2:35 PM #42524In reply to: Missing Field
Daniel Leu
ParticipantPatrice, just quoting Brendan from an earlier post:
Hi Patrice,
If you email me a backup of your document I can probably restore it.
or check the “Restore deleted items…” function in the File menu to see if it appears there.
Sorry for this trouble.
Thanks,
Brendan
Brendan can be reached at support@tapforms.com.
I have never encountered lost data as you describe it. Do you use any formulas or scripts that might have an unwanted side effect?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks -
AuthorSearch Results