Hi,
I’m a real newbie at related databases period, but with help I’ve had some success & I’m understanding more, but I have another issue that after much time searching these forums, reading the 101 & 102 etc. and many attempts is still not coming right, so a steer would be really appreciated.
I’ve created a new form for notes as a child of the main form using a 1:many.
I’d like to track who created the note record & who last made a modification to it.
The later is solved easily with the Modified by device field type, but I’m struggling to set the original creator with a fixed value. My original thinking was a calc or script that tested if a text field for “Created by:” was empty and referencing the Modified by device value if empty & ‘undefined’? if not?
It doesn’t seem possible to reference that field type within a calculation or script, at least not in a way that appears obvious to me?
Do I need to think about this in a different way?
Thanks, Stephen.
Ok, my bad…
RTFM!
The answer is here all along… Tap Forms Scripting 101.
So there are two types of scripts… I had created mine in the wrong place. It is now made as a field script. So answered half of my own questions. D’oh!!
Now, if I can just find out how to return the record colour to default appearance…
I’ll keep looking until someone can chip in with a clue, maybe I’ll be back to solve my own issue again! lol
Doing some serious learning today! ?
Stephen.;)
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.