Brendan Hi Ok Ill think about this. I guess there is no problem to insert a Record in a different form than the form with the field script, correct ? Ill give it a try and post here the results.
Bernie
Field scripts execute whenever a value they’re monitoring changes. So if you’re entering data anyway, you could monitor for that change and insert the records you want at that point. You don’t even have to be doing anything with the field you’re monitoring. Just to know that it has changed and the script will be triggered. But no script will get triggered just by viewing a record.
Brendan Hi thanks for the opportunity to explain. I will try to be brief but somewhat detailed.
I have 3 linked forms
1. Drill Description
2. Drill Results (One record for each time a drill is executed)
3. Drill Total Results (One Record for each Drill with accumilated totals of rows in number 2 above. Totals are calculated using Calculation of linked fields
One time process : Load a description for all possible drills in Form 1 assign a ‘DrillID”
Eacb time a drill is executed :
1. Open form 1, drill description
2. Pick a drill and click on the + next to linked Form Drill Results (2)
3. Enter Results and either pick a new Drill Description or exit
The Problem as I see it. The records in table 3 (Drill Total Results) need to be manually added the first time a drill has results which for me, is extra work on the user part I like to avoid. As if the user forgets to pen the Form and add a row, no totals will ever be displayed.
What I have done is write a script that will look at all the records in table 2 (Results) and check if a Record exists (by Drill ID) in Table 3 (Totals), if exists, do nothing, if not exists add new row. Now when a Drill Description is open the linked forms for both Results and Totals will be present and viewable.
This script has to be executed manually using the Form Run Script command. It would be nice if it could be executed ‘ON Open’ automatically.
Or is there another way to accomplish script execution without user intervention?
Hope this is clear.
Thanks for the help
Bernie
These MOASS Ladder templates have gotten some revisions..
(1) Mainly I had forgotten to connect the fractional shares field, and when corrected that blew three scripts, all revised.
(2) Then also I have added a way to re-use the Goal Section within multiple Ladders. Usually your goal list would remain static.
New versions below.
Are there any available hooks in a Form such as ‘ON Open” o ‘On Close’ etc. Where one could have a script execute based on this event?
Thanks
Hi David,
You can do this with a Calculation field, but it would be much easier to understand with a Script field.
Just off the top of my head without actually testing it out, here’s a script that “should” work:
function getResult() {
let margin_id = 'fld-....';
let money_id = 'fld-....';
let margin = record.getFieldValue(margin_id);
let money = record.getFieldValue(money_id);
var result = 0;
if (margin < 25)
result = 0;
} else if (margin >= 25 || margin <= 27) {
result = money * 0.08;
} else if (margin > 27 || margin <= 30) {
result = money * 0.1;
} else {
// not sure what happens if margin is greater than 30?
}
return result;
}
getResult();
So add a Field Script and copy this code into your script and then change the field IDs appropriately to match the actual field IDs of your own Margin and Money fields.
It should work.
Thanks,
Brendan
Ok, I am trying to learn some scripting for the calc field but I am running out of time in my evaluation process of TF (which so far has been amazing) and we have a use case that we can do in Numbers but unsure if we can in TF.
I am trying to do an if/then usineg two fields. One is a Margin field (which is a number field) and the other is a money field. Basically I am trying to get a final calculation from certain numbers. It looks like this
I the (Margin) is <25 then 0
If the (Margin) is > or equal to 25-27 then (Money) * .08
If the (Margin) is > or equal to 27-30 then (Money) * .10
Is this possible in the calculation field and if so…If someone would be willing to show me how it will help a ton with me starting to understand exactly how this scripting works.
Oh, it’s just a matter of the wrong field IDs in the script. I guess I used an archive of the form you sent me a while ago to write the script. You also renamed the Kalvningar field to Antal kalvningar so that took me a minute to find it again.
var kalvningar_id = 'fld-cdb4431a905f4b1dbaa750b07a63b6f1';
When you see an error in the console, first check to make sure all the field IDs in the code match the field IDs on the left. You can select a field and see its ID below.
Hi Stig, instead of sharing a TapForms template, could you share a TapForms archive of a document that contains entries for just a few animals? I tried to see what the script does, but it returns an error. I don’t know if I missed to enter some data or if there is an issue with the script. Having a TapForms archive with known data would make debugging much easier. Thanks!
Cheers
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thank you Brendan for your efforts.
Unfortunately I have to bother you once more because nothing shows up in the added script fields.
Regards
Stig
Attachments:
You must be
logged in to view attached files.
Hi Victor,
It looks like I never really flushed that one out. It’s just returning exactly what you see. The search object with it’s ID and name.
The primary use of AppleScript in Tap Forms would be to run a script within Tap Forms. And from there you can reference a search and get its records and perform some operation on the results.
Thanks,
Brendan
Hi Sebastian,
1. Custom layouts are fixed according to the x, y, height, and width settings you provide for it. There’s no workaround to make them dynamically sizeable. Sorry.
2. The only way to show data from a Link to Form field in a Table or other Link to Form field’s table view is to add a Field Script which loops through all of the child records from the relationship and appends them into a big string to display. But even then there won’t be a whole lot of room because you can’t adjust the height of a row, only the width of the column. The Script Editor has a built-in snippet called Child Records Loop which is a starting point for building that kind of a function.
Thanks,
Brendan
It looks like @Sam has been busy lately. You might browse his GitHub repository where he has amassed different tools and scripts supporting TapForms: https://github.com/pasamio/tftools
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
In the Applescript Tap Forms dictionary there is the following:
search n, pl searches : A search item
elements
contained by forms.
properties
id (text, r/o) : The unique identifier of the search.
name (text) : The name of the search.
Is this for running a saved search, so that the result is that Tap Forms shows the records which match the criteria for the saved search?
Also what is the syntax for this AppleScript item?
Any help would be gratefully received.
Brendan,
Thank you for the response. It has forced me to find a work around.
I know it is possible with a File Attachment field to click on the Add File icon (+) and then add as many files as you wish. However this is not reachable by the menu or by the keyboard – only a mouse or trackpad will work.
I post the following in case it is of use to someone else.
The workaround provides:
1. selecting the record in Tap Forms
2. in Finder, selecting the files to be attached.
3. running a Keyboard Maestro macro using the For Each action which:
(a) copies the filename and path of each file selected to the system clipboard
(b) runs the Tap Forms Form Script (via a short AppleScript script) on each filename with path copied ot the system clipboard
This is has the benefit that it can be activated via a keystroke and there is no need to worry about the names of files being different.
The final Tap Forms Form Script is as follows:
`function Add_Alias() {
var ClipBoardName = ”;
var file_attachment_id = ‘fld-1f7f08ca22de4884b5a7aa6b52a74251’;
var ClipBoardName = Utils.copyTextFromClipboard();
var url = “file://” + ClipBoardName;
console.log(url);
record.addFileFromUrlToField(url, file_attachment_id);
document.saveAllChanges();
}
Add_Alias();`
The Keyboard Maestro script is attached as a PDF.
Attachments:
You must be
logged in to view attached files.