Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
June 18, 2021 at 2:27 PM #44644
In reply to: Split note field?
Sam Moffatt
ParticipantOn a similar note, I do something similar except the data I generally pull in is free form and I use a table field with a “Key” and “Value” fields inside it. It’s a similar sort of script except that you use fixed name for the key/value field names and an extra table field. There is an example of using a link to form/table fields and
addNewRecordToFieldin the Get Movie Details from TheMovieDB API. If you know the keys are going to be unique, I also have a helper script on GitHub that scans a table field (also works with link to form fields) and expects a key/value field structure to then add only entries that are missing.June 18, 2021 at 12:22 PM #44641In reply to: Split note field?
Brendan
KeymasterHi Emil,
This can be done with a script.
Here’s an example that takes the lines from a Note field and splits them into an array and then loops through the array of lines and writes each line to a separate field. I’ve made some assumptions here such as your field names have a pattern of “Field 1”, “Field 2”, “Field 3”, and so on.
function Split_Note() { var note_id = 'fld-c711358a858443c8805c8c98c71a03b4'; var note = record.getFieldValue(note_id); var field_prefix = "Field "; if (note) { var lines = note.split("\n"); console.log(lines.length); var fieldIndex = 1; for (line of lines) { let field = form.getFieldNamed(field_prefix + fieldIndex); if (field) { console.log(field.name); let field_id = field.getId(); record.setFieldValue(field_id, line); } fieldIndex++; } } form.saveAllChanges(); } Split_Note();You can see the result of running this script in my example screenshot.
Attachments:
You must be logged in to view attached files.June 18, 2021 at 7:26 AM #44640Topic: Split note field?
in forum Script TalkEmil Mitchell
ParticipantDear all,
I am rather new when it comes to technical database terms and I am hoping someone can help.
I have a note field with approximately 5 lines of text. I have come to the conclusion that it would be better to have each piece of text within the note field within its own field.
Is there a way to split the information within a field into separate fields using some technical scripting magic, rather than having to go back and edit them all manually?
Thank you for your time!
June 16, 2021 at 2:36 PM #44624In reply to: Check Mark Multiple Records
Daniel Leu
ParticipantOnce you have your group of records using search, go to the multi-column view, set the first value and then click on the yellow dot and move it down. This will copy the value to the other fields.
Another option would be a form script.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksJune 12, 2021 at 11:33 PM #44611In reply to: Get Movie Details from TheMovieDB API (Help Needed)
JCK
ParticipantOhhhh kay. That makes sense. I realize now that I was calling the convertIMDBtoTMDB function at the wrong time.
How do I add to a variable? Or is this something I’m confusing from coming from Shortcuts on iOS.
The use case I’m running in to is for films with multiple directors. I’ve figured out how to loop through the results to get the names of both directors listed in the console, but I’ve run into a issue trying to add the positive results together.
function getCrew() { var fullcredits = fetchCreditsFromURL(); if (! fullcredits) { console.log("Request to get credits failed"); return []; } return fullcredits.crew ? fullcredits.crew : []; } function getDirectors() { let crew = getCrew(); for (let crewMember of crew) { if (crewMember.job === 'Director') { console.log(crewMember.name); } continue; } }In Shortcuts, I would add an “Add to Variable” option, but there doesn’t seem to be anything like that in javascript. Adding a return function at any point seems to stop the loop, or only give the last result.
Ideally I would like all positive results to be returned in a single string that I could add to a field. What am I doing wrong?
June 12, 2021 at 8:57 AM #44608In reply to: iOS: Display linked child records?
Redrock
ParticipantThanks much for all the info, Sam. I appreciate it. I didn’t realize TF scripts use java. I won’t tell you how long it’s been since I’ve coded, lol.
As a former MS Access and HanDbase user, I vote for a TF enhancement to have the ability to create views where linked records can be created, edited, and displayed with their parent records—it’s a basic relational database function that could put TF at the head of the pack.
June 11, 2021 at 11:08 PM #44603In reply to: iOS: Display linked child records?
Sam Moffatt
ParticipantFirst step is to check out the JavaScript API to get a feel for some of the stuff available.
Next stop I’d suggest is to check out T.L. Ford’s JavaScript tutorials.
If video is more your jive I’ve got a YouTube channel with some resources including a intro to scripting and a script field deep dive. There is also a video on link to form fields and scripting that might help as well.
The forum has a bunch of great examples of how to use the scripting in Tap Forms. There was a recent post on using Markdown for contracts which leverages a script field to generate some Markdown output including leverage a table field. From a scripting perspective, link to form fields and table fields behave similarly so anything that works with a link to form field will work with a table field and vice versa.
Hopefully this helps!
June 11, 2021 at 2:39 PM #44602In reply to: iOS: Display linked child records?
Redrock
ParticipantWell, that explains why I couldn’t figure it out. I actually wanted to populate the linked form from the parent, in addition to simply displaying them.
I tried using a table, but while it pulled over the child record names, there was no data.
Scripts, huh? Sigh. Could you please point me to a reference guide?
Thank you for the reply!
June 11, 2021 at 2:16 PM #44601In reply to: iOS: Display linked child records?
Brendan
KeymasterHi Redrock,
There’s no custom layouts function on the iOS version of Tap Forms.
And linked records always display in a separate list on iOS. At some point I might change that to display like the Table field does, which displays inline on the parent record as a table of sub-records.
So if you need to display things visually like that, you would want to use a Table field instead of a Link to Form field.
Or alternatively, you could write a script which picks out a field from the Link to Form field’s form and displays that in a list of values on the parent record.
Thanks,
Brendan
June 10, 2021 at 11:38 PM #44595In reply to: Get Movie Details from TheMovieDB API (Help Needed)
Sam Moffatt
ParticipantYou’re using a bunch of global variables, each time you do
var thingthenthingbecomes a global variable when you’re doing it outside of a function. That’s why you can use the variables almost anywhere though in general that’s not best practice. The prompter uses this technique in part because it’s an async call but once we’ve stepped out of that, it’s best to use actual arguments and return values. When you dovarinside the function, it’s scoped to the function and not accessible outside it. Let’s rewrite this slightly to use an input variable forinputIDand return a value:function convertIMDBtoTMDB(inputID) { fetchURL = ` https : // api.themoviedb.org/3/find/${inputID}?api_key=${tmdbAPI}&language=en-US&external_source=imdb_id`; var tmdbResp = Utils.getJsonFromUrl(fetchURL); var tmdbID = tmdbResp.movie_results[0].id; console.log(JSON.stringify(tmdbID)) if (! tmdbID) { console.log("Request to get code failed"); return ""; } else { return tmdbID; } }Same function except we’re accepting an inputID as an argument and then returning the
tmdbID. I left thetmdbAPIalone because I feel it’s a constant more than a variable and something you’d want to leave in global scope. Where possible you want to explicitly tell a function what it’s inputs are, in this case literallyinputIDbut even in the other places it’s better to be explicit:function fetchCreditsFromURL(itemID) { fetchURL = `https://api.themoviedb.org/3/movie/${itemID}/credits?api_key=${tmdbAPI}&language=en-US`; return Utils.getJsonFromUrl(fetchURL); }That way you know where a variable is coming from and you’re less likely to have a variable in global scope accidentally trashed. Nothing in Javascript is straight forwards so I was looking for a good resource and this page on demystifying Javascript variable scope has some great details on how it works and where some of the pitfalls are.
Instead of relying on the global changing, assign it to a variable in the right scope and then pass it along to anything else that needs it. Hopefully that helps get you a little further :)
June 10, 2021 at 1:14 AM #44591In reply to: Shopping List
robinsiebler
ParticipantOk, I added the checkmark field. In addition, I added a Search Filter for unchecked items and a script you can use to remove checked items.
Attachments:
You must be logged in to view attached files.June 9, 2021 at 3:13 PM #44585In reply to: Shopping List
robinsiebler
ParticipantSO just to verify:
1. If you manually add an item to the Shopping List, the categopy is not added.
2. If you manually run the script, the category is added.
3. If you run the Shortcut the category is added.If all of that is true, I think all that I have to do is a add a field script to the Shopping List form that will update the category.
I will try that and get back to you.
June 9, 2021 at 3:06 PM #44584In reply to: Shopping List
Roger Cuthbert
ParticipantI added Naan manually and the shopping list record did not add the category.
I created a shortcut as you suggested. Added Naan to the clipboard and ran your script and the category is added correctly.
June 9, 2021 at 12:51 PM #44583In reply to: Shopping List
robinsiebler
ParticipantAnd the item you are adding is in the Product form and has a category? If so, could you try this? Add the item in question to the clipboard and just run the script ‘Get Item from Clipboard’. Let me know what happens.
June 9, 2021 at 2:33 AM #44572In reply to: Shopping List
robinsiebler
ParticipantI fixed some bugs and added a notes field. I also added another 100 products to the products form. In addition, I updated the Shortcut to prompt for a note (see screen shot). However, Siri is stupid! If you say ‘No’ when you are prompted for a note, Siri bails on the entire script! So, instead of saying ‘No’, say ‘Later’ and you will not be prompted for the note.
I should mention that you have to manually create the Shortcut using the attached screenshot as a guide. I have no clue how to share a shortcut outside of the Apple ecosystem.
Attachments:
You must be logged in to view attached files. -
AuthorSearch Results