Daniel, yes, you’re right, this script is too inelegant and ineffective to be useful to anyone but me. I’ve shown it almost as a curiosity while we wait for the right way to do it.
Other than that, thanks again!
Wow, this is scary….
>click button 4 of UI element 2 of row 4 of table 1 of scroll area 2 of splitter group 1 of splitter group 1 of window 1
>click text field 1 of UI element 1 of row 2 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of sheet 1 of window 1
>click button 3 of sheet 1 of window 1
I would not want to maintain this, at least with your comments it is a bit easier! It is great that you have found a way to automate attaching a file as an alias.
Once the record.addFileFromUrlToField() issue is fixed, you can call the Tapforms’ script interface using tapformz://script/db-xxxx/frm-xxxx/Test+Script?option1=A&option2=B.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
This is a very simple (and primitiv?) Applescript to attempt to add a single photo alias to a ‘File Attachment’ field on a single record.
The next step will be an automated ‘repeat with’ from a list of photos to a bunch of records in Tap Forms.
Waiting for a better and cleaner solution with an script in Tap Forms.
With this code, it works to assign a single alias to a single field. It’s a small thing, yes, just to keep going and learning!
-- 220310B - 'TF_AS3' (WIP)
-- NOTE: the 'POSIX file' depends on your own photo folder path.
-- NOTE: the value of 'row 4' (in the first 'click button' line) depens on the 'File Attachment' field position.
-- NOTE: the parameters of 'click text field…' line and 'click button 3 of sheet…' depends on the own photos path, obviously.
set f to POSIX file "/Users/ricardcasalsalexandri/Desktop/fotos-test-2/19770101.JPG"
set sourceFile to f
tell application "Finder"
activate application "Tap Forms 5"
tell application "System Events" to tell process "Tap Forms 5"
click button 4 of UI element 2 of row 4 of table 1 of scroll area 2 of splitter group 1 of splitter group 1 of window 1
click text field 1 of UI element 1 of row 2 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of sheet 1 of window 1
click button 3 of sheet 1 of window 1
end tell
end tell
(I tried to attach the script – also as a zip – but I can’t figure it out)
First of all, thank you for this excellent program.
I have a form with a lot of records: 10 years, day by day, one photo per day. At the moment I prefer that the images are outside of Tap Forms, and now they are, as an alias, in a “web-website” field.
I’m new to Javascript and I’m trying – probably wrongly – to copy the link in the “web-website” field to a “File-Attachment” field, with this script, trying in 2 ways:
function CC1 () {
// Get image-link-from-web-field
let image_id = 'fld-8f9c8612cbc04ebfb422576213cebf74';
let image_link = record.getFieldValue (image_id);
// way A - Copy to file-attach-field-as an alias
record.addFileFromUrlToField (image_link, 'fld-05f12a9a7da74079b354a02e7c5bb305');
// way B - Copy to file-attach-field-as an alias
//record.setFieldValue('fld-05f12a9a7da74079b354a02e7c5bb305 ', image_link);
form.saveAllChanges ();
}
CC1 ();
What am I trying to do is possible? Or should it be done manually by clicking “Add File Alias”icon?
Thanks a lot! Ricard Casals
Or maybe use a field script that uses record.getRecordColor():
function RecordColor() {
return record.getRecordColor()
}
RecordColor();
Now you have a hex value that you can search on.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I have an iMac and a Macbook. Something went wrong in my database a couple of months ago and I only noticed it this morning. A form with scripts had been erased. Anyway, I had a backup and was able to restore it on my iMac.
But before proceeding, I inactivated syncing, deleted the iCloud syncing data from my iMac. Turned off syncing on my Macbook too (from Tapforms) and deleted the local copy.
At this point, my database is on my iMac. I re-enabled syncing. I saw that the last upload date and time was corresponding to when I re-enabled syncing, after a couple minutes. So, on iCloud, it would seem that all is good.
On my Macbook, my database won’t sync fully. When I launched Tapforms, my database appeared with a cloud sync icon. When I try to open it, it shows an empty database. I’ve been patient, waited a long time, closed the database and waited, but the file never goes over 2.6 mb in the Finder. The real file size is 154 mb (or close to).
What else can I do to get my database from my iMac to my Macbook.
Note : I know the database is on iCloud sync because on Tapforms for iPhone, the database is all there, up to date.
Thanks,
Ray
Hi Daniel,
Your script works perfectly and changes the colour of the record index listings.
However, I would like only to change a specific field within the record layout.
Sorry for not making myself clear.
I have potentially 2 people in one record, ie Mr & Mrs, so I would only like to amend their specific ‘name’ entries to black/yellow if one of them passes away.
Is it possible to amend the colours of a specific fields background & text?
Many thanks
Just a little update to my field script:
function recordColorScript() {
const yes_no_id = 'fld-xxx';
const yes_no = record.getFieldValue(yes_no_id)
if (yes_no == "Yes"){
record.setRecordColor('#00FF00') // green
console.log("set color for yes")
} else {
record.setRecordColor('#FF0000') // red
console.log("set color for no")
}
document.saveAllChanges()
return yes_no
}
recordColorScript();
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
The Javascript API is documented at https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api. Things like object.text.color or object.backgroundcolor are not supported. But there is record.setRecordColor('#cc9900');
Maybe this works for you:
function recordColorScript() {
const yes_no_id = 'fld-xxx'
const yes_no = record.getFieldValue(yes_no_id)
if (yes_no){
record.setRecordColor('#00FF00') // green
} else {
record.setRecordColor('#FF0000') // red
}
document.saveAllChanges()
}
recordColorScript();
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thanks for info. It makes me understand now that there is no need for a script.
I can manage everything without.
Thanks for that Brendan.
I followed your instructions and the Pick list does show a small coloured bar to the left of the selection but when you click on the selection the coloured bar doesn’t appear in the field.
It would be much easier if the record was blatantly obvious showing the person was deceased.
ie the field background colour turns Black.
I was playing around with script trying to achieve the colour changes but most web ‘help’ refers to HTML/CSS options. There is little help with regards to syntax for pure javascript, or there are conflicting ‘color’ coding syntax versions.
See my feeble attempt at scripting below. :)
Do I just need to correct the syntax for ‘colour’ related code for TF? …
function Cl1_expired() {
// Change text box colour when checkbox is ticked
var cl1_deceased = record.getFieldValue(‘fld-8e6c8ac1b14446088d6f4443f103efd7’);
var cl1_full_name = record.getFieldValue(‘fld-f86ccf72fcf848669d17db555ca697f3’);
if (cl1_deceased = true) {
// true condition;
cl1_full_name.backgroundcolor = “black”;
cl1_full_name.text.colour = “yellow”;
} else {
// false condition – do nothing
}
}
Cl1_expired();
Hi John,
I would suggest instead of a Checkbox, use a Pick List. In a Pick List you can assign colours to the values. Then on the Form properties, set the “Record Colour Field” option to be the field you’ve assigned that Pick List to. Then when you select a value from that Pick List in your record, Tap Forms will display a coloured bar next to the record. So then at a distance you can easily see which records represent deceased individuals.
No scripting required.
Thanks,
Brendan
Hi,
I’m looking for a way to change a name field when a person is deceased.
I currently have a ‘Full Name’ field (concatenated from other name fields, with a grey background) and a ‘Deceased’ check box.
When the check box is ticked I would like the ‘Full Name’ field to have a black background with yellow text.
Sounds simple enough but I’m a newbie to scripts so not sure how to trigger the change when the check box is ticked.
Any help would be gratefully appreciated.
Many thanks
The Swedish farmer has received successful help with earlier scripts.
But there is a need for one further script and the knowledge in JavaScript is still nonexistent.
So help with a form script is most welcome!!
A document template of “Djur” is enclosed.
This is the background:
In the form “Kalvningar” are calves from the season listed. They will be split into three groups:
– female calves kept for breeding
– female calves for sale (the rest)
– male calves for sale
The script should perform the following:
Go through all the calf records and check:
1. if a female calf and the field “Utgångsorsak” IS NOT empty (breeding info already entered): enter a transaction date in the field “Utgångsdatum” for each record and make a copy of these records with information in fields “Utgångsdatum” and “Utångsorsak” deleted ie. empty and transfer these copies over to the form “Rekryteringsdjur”.
2. if a female calf and the field “Utgångsorsak” IS empty:
– enter a sales date (to be typed in) in field “Utgångsdatum” and the information “Försäljning” in field “Utgångsorsak”.
3. if a male calf and the field “Utgångsorsak” IS empty:
– enter another sales date (date of sale for males and females not the same) in field “Utgångsdatum” and the information “Försäljning” in field “Utgångsorsak”.
If both the fields Utgångsdatum” and “Utgångsorsak” IS NOT empty: go to next record.
Finally should the group information in the field “Grupp” in the form “Rekryteringsdjur” for all records in that form be deleted so that the field is empty.
Now the data base is prepared for a new calving season.
Attachments:
You must be
logged in to view attached files.
Sam, I regard the Kalva-script as a big success.
Thank you very much for your help.
As I indicated in this thread on 12 feb there is a need for one further final script in the document Djur.
If you have time and still got inspiration I would ask you to help me with that one as well.
This thread is too long so I intend to start a new one for that script.