Hi, I’m looking to achieve something similar to this thread, using Bredan’s example above I have entered the following code, but I’m getting unpredictable results, plus my no colouring state is clearly not right!
Outcome should be, checkbox field true, record red. Checkbox field false, record not coloured.
So, for the time being I’ve set my no colour state to green, just so I can see a change. The script appears to give the correct result when triggering manually with the play button at the bottom of the list of scripts, but not running on change of value of the check box field.
Any guidance appreciated!
Stephen
function Record_Colour_Script() {
var number = record.getFieldValue('fld-5b558c4b243d4d428355eec24dadfb66');
var colourHex = '#FF0000';
var clear = '#FFFFFF00';
if (number > 0) { record.setRecordColor(colourHex); record.setRecordColor(clear);
}
form.saveAllChanges();
}
Record_Colour_Script();
The AppleScript feature is still there, but it was primarily meant for firing off a Form Script in Tap Forms from an AppleScript. Although you can also query for a list of forms and such. The AppleScript dictionary will tell you what’s available.
Thanks, man. And is the Tapforms AppleScript Library either a thing of the past, figment of someones imagination?
Hi Mike,
The scripting in Tap Forms is designed more to facilitate working with your data within the database. But there are some Utils functions which might help you with something like this by using the Utils.openUrl() function. You could build a mailto: link in code and use a script to call it.
Thanks!
Brendan
Hi, Brandan and TapForms community.
I have an AppleScript I developed a few years ago for sending emails to selected entries in Mac Contacts that I was looking to migrate to TapForms.
This script looks like this:
set myMessage to "Hi, here's a newsletter...
Thanks and I hope you are doing magically and wonderfully.
Blessings, Mike.
https://example.com
"
set mySubject to "Engaging Subject"
display dialog "Please select the recipients in Address Book/Contacts"
tell application "Contacts"
set theContacts to selection
repeat with contact in theContacts
set contact_name to name of contact
if first name of contact is missing value then
if name of contact is not missing value then
set contact_addressed_as to name of contact
else
set contact_addressed_as to "stranger"
end if
else
set contact_addressed_as to first name of contact
end if
my send_message(mySubject, "Hey " & contact_addressed_as & ",
" & return & myMessage, value of first email of contact)
delay 10
end repeat
end tell
on send_message(theSubject, theBody, theAddress)
tell application "Mail"
set theNewMessage to make new outgoing message with properties {sender:"Mike iLL <mike@madhappy.com>", subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
make new to recipient at end of to recipients with properties {address:theAddress}
delay 3
send
end tell
end tell
end send_message
display dialog "Sent batch ending with " & contact_name & "." buttons {"OK"}
I changed the App name to Tap Forms 5, but before I get into the current error (okay it’s Expected class name but found identifier), I had seen a reference to a “Tapforms AppleScript Library” somewhere in the forums, but can’t find that.
Additionally, I’m more adept at JavaScript and see that there’s an API for using that. Are there resources I should know about beyond the API reference in the docs?
Thanks and I’m excited to, after three years, finally be getting back into using the app (which is up to date).
Hi Wilma,
You can do this, but not directly. You just need to add a Script field to your form and add in the following code to the script editor:
function photoCount() {
var case_cover = record.getFieldValue('fld-your-field-id-goes-here');
return case_cover.length;
}
photoCount();
This will give you the number of photos in the Photo field. You can then create a Saved Search which looks at this and checks to see if the value is greater than 0.
You’ll need to replace the fld-your-field-id-goes-here part with the Field ID for your own Photo field. You can get that from below the Fields list when viewing the list of fields in your form.
Thanks!
Brendan
I’m having a weird issue with a couple of the forms in one of my projects.
After ‘some period of time’ (maybe a day or two?) my records seem to lock in such a way that you can change their data, but the moment you hit the ‘Refresh Records List’ button it loses all your changes and reverts them back to their previous state.
If I add new fields, such as scripts, it does the same. I can add a script field to fill out a text entry, hit the ‘Recaluate Scripts button’ for the record and it works – it even shows the new data on the records list. But next time I hit the ‘Refresh Records List’ button it will wipe the script output field to blank again.
If I make a new record it works fine at first, but then after a while that record will stop accepting new changes.
I have no ‘global scripts’ at all.
Not sure what might be causing the issue, any ideas anyone? If what I’m describing isn’t clear I can maybe take a screenshot or two to illustrate.
Here is an example (with german words), which works for me:
function Record_Colour_Script() {
var erledigt_id = record.getFieldValue('fld-0f62df9131e64cdeae7b1a98580e700b');
var aufgehoben_id = record.getFieldValue('fld-f7738e96b4154742965b96ea5c697e31');
var gestrichen_id = record.getFieldValue('fld-a108b72455cb4fc8aa6354646e01fe1b');
var nicht_abrechenbar_id = record.getFieldValue('fld-5b27768928a3423ebddd542e3e05823f');
var abgerechnet_id = record.getFieldValue('fld-db41b041736543c697fc78671b0f2777');
if ((aufgehoben_id == true) || (gestrichen_id == true)) {
colourHex = '#9D9D9D'; // rot
} else {
if ((erledigt_id == true) && (abgerechnet_id == false) && (nicht_abrechenbar_id == false)) {
colourHex = '#ff9933'; // orange
} else {
if ((erledigt_id == true) && ((nicht_abrechenbar_id == true) || (abgerechnet_id == true))) {
colourHex = '#008000'; // grün
} else {
colourHex = '#ffff66'; // gelb
}
}
}
record.setRecordColor(colourHex);
form.saveAllChanges();
}
Record_Colour_Script();
Hello all,
I am trying to follow Brendan’s instructions here: https://www.tapforms.com/forums/topic/programmatically-set-record-color/
By using the following code:
function Change_Record_Colour() {
var ffs = record.getFieldValue('fld-c629f095416d4df5be8e1a7de4fd81ba');
if (ffs) {
record.setRecordColor = '#ff0000';
console.log("red");
} else {
record.setRecordColor = '#ffffff';
console.log("white");
}
form.saveAllChanges();
}
Change_Record_Colour();
But it is not actually changing my record colour.
The console is recording the correct values, so I know my *if* conditions are working OK.
I am able to change the record colour using the colour picker at the bottom of the record, just to the left of the refresh arrow icon and the size of the record in KB.
Am I doing something wrong?
Thanks,
Phil
I had memento too. While you can export to cvs from memento the images get dumped as URLs. You will be able to import the memento csv file to TF but i don’t know about the images. And in memento if you saved descriptions/notes it exports as funky coded stuff.
I never used memento to send to google sheets. I looked at the value of it but never needed to use it that way.
you can export TF to csv and send it just about anywhere. I imagine with scripting etc you can run this function programmatically.
But I would also go as far as to say you could probably recreate your entire application with TF and run it on Mac. ;)
good luck
I am looking to move from an android devices and one of the biggest hold ups is the fact that I use memento database as a database. Today with memento I use a database to catalog “inventory” items daily and when I am done for the day I sync with Google Drive/Sheets from their I can import my data from the sheet and drive into my line of business application.
What I need to know is if I can sync the tap forms database and images to a “cloud” server and then download a csv and images to a PC as my line of business application only runs on a PC. Today my csv/excel file when exported has the following columns
Inv #, Title, description, value, category, image names, image urls
Is this something tap forms can do?
Thanks in advance
Sometimes you want to look at the contents of the parent linked form whilst you are inside the child record. If you’re using custom layouts this makes it a little easier to pick up and embed targeted values. I also have used calculation fields to project in the parent title to forms so that I can see it in the record list.
You can set a calculation field to calculate only once which should happen when the record is created. Whilst I’ve not directly tested this, in theory if you reference the parent form fields it should capture the value as that point in time and then lock it as uneditable. You would need to have created the record from the parent record and would only obviously only work for a single parent record.
A pattern I use when working with script fields is to have them update actual fields and then check to see if those fields have a value already. It means you can reset their value manually if you really want to or you could delete the value to have the script reset it. That allows you to “fix” things or change them easily. I also have a pattern where I use the script field itself to store state as well by return a JSON encoded value for the script field and then reading the script field back to check the previous state.
A common pattern for maintaining temporal records is effective dated records. If that sort of model is important to you then you could store a shadow copy of your form that is effective dated and then use a script field to replicate the current field values. It generally is more effort than it’s worth though and future dated records likely wouldn’t work properly.
Hope this helps!
You use a Calculation or Script field to copy the value from the parent record into the child record so that Tap Forms can provide the ability to search and sort the child records based on values in the parent record. That’s why Tap Forms copies the value using the Calculation field as a way to do that. You can tell the Calculation field to only evaluate one time. Then Tap Forms won’t put in a new value for it if the Calculation field already has a value. A Calculation field is just like a normal Text, Number, or Date field, except that its value is derived from the formula. The value is still stored just like the other field types.
I’m importing some records of clients via csv. One column in the csv contains multiple appointment dates per client.
I want the clients to go into my Clients form. The Clients form has a Link to Form field called Appointments. It’s a 1:M field and “Show Inverse Relationship” is checked.
I need the clients to be imported as records in the Clients form, and the multiple dates per client from the csv to be entered as child records in the Appointments form.
I don’t think there’s a way to do that all in import, so I figured I’d:
1. Import the csv into Clients, while creating a new field “Dates to Process” to capture the multiple appointment dates
2. Use a script to loop through “Dates to Process” and create the appropriate records in Appointments
For step 2, I’m pretty sure I can loop through the “Dates to Process”, but I don’t know how to apply each date as a new record in “Appointments” that’s associated with that client in the parent Clients form. I see that in the script editor, I can tap on one-to-many icon next to Appointments, and get its ID, but after that, I’m at a loss.
Any help would be appreciated!
Additionally you can use a “Calculation” field in the “Role Map” form to copy across details from the consultant table. This should get updated automatically when the consultant record is updated though there are a couple of times where I’ve confused TF enough for it not to propagate the changes (the exception not the rule).
Sorry for resurrecting this thread, but I did have a question about the advice above (for my own understanding).
Since the underlying data (the “truth”) is already stored in the related form, why would one copy the data into the calculation field? Is this not redundant as opposed to, say, referring to the original data field using a script?
One possible advantage of doing that (at least that I could identify) would be to transactionally put the related data into a calculation field and then not update the field unless directed to do so by the user. This would have the effect of setting the data at “time zero”, allowing the underlying data (in the related field) to be updated without modifying the related record. In situations where one needs the correct historical record AND the ability for the related forms to have updated information as time goes by, this could be an advantage. However, in my limited knowledge, this is not the way Tap Forms works, correct?
Thanks for any insights.