Hi Andy,
You could definitely write a Form Script to do this. Or you could also use the Advanced Find & Replace function to do this. I’d make a backup of your document first whatever you do though.
With the Find & Replace method you could start with searching the Rating field for 5, then set the value to 10. Then search for 4 and set the value to 8, then search for 3 and set it to 6, then 2 setting it to 4, then 1 setting it to 2.
You have to do it in reverse as described above because if you go the other way, you’ll end up changing values you already changed.
Or here’s a Form Script you can use for it:
var rating_id = 'fld-3baff54c8e164de9b9ad3f0fbb040bc6';
var records = form.getRecords();
for (var index = 0, count = records.length; index < count; index++){
var aRecord = records[index];
var rating = aRecord.getFieldValue(rating_id);
aRecord.setFieldValue(rating_id, rating * 2);
}
form.saveAllChanges();
You need to use your own rating field ID though (e.g. ‘fld-…..’). The above is specifically for my test form.
But make sure you run it only 1 time otherwise you’ll double the rating values again.
Hello
My databases were imported from Bento. I have a rating field in most of my forms which are all 0-5 stars, because that is what Bento provided. I would like to make them 0-10 stars which I can do in Tap Forms but this means changing all the existing values: I have thousands of records.
Is there a way to automatically double the ratings value in all records please? I have looked at scripts and at this forum but can’t find anything obvious that would do it. The closest I could manage was to make a new calculation field that takes the existing rating and doubles it. However, this does not allow me to enter data directly so it would not enable me to have a rating of say 7 because I can’t enter 3.5 in the original.
Many thanks
Andy
Hi Izzy,
Since 2011 I’ve added many new features to Tap Forms (the original post year). One thing you can do now is you can add a Script field which can process the value from another field in your form to do some manipulation of the values.
So you could write a small script that removes any occurrence of the word “The” in the movie, book, or song title and returns that in the Script field. Then you can sort your records on the Script field values.
Here’s a script that will do just that:
var movie_title = record.getFieldValue('fld-987c9aac738a4f0fa1d18395902b3fb1');
if (movie_title.startsWith('The ')) {
movie_title.replace('The ', '');
} else {
movie_title;
}
So it will search for the first occurrence of ‘The ‘ and replace it with nothing, effectively removing it. And the if statement checks to make sure it only does that if ‘The ‘ appears at the beginning of the movie title.
Hope that helps!
Brendan
Hi Brendan,
I try to assign the current date to a field using a script.
First try:
theRec.setFieldValue(date_sold_id, Date());
Doesn’t show anything. If I change date_sold to a text field it works. Then I tried to get the date number:
theRec.setFieldValue(date_sold_id, Date.parse(Date()));
Doesn’t work either. But something like this works:
theRec.setFieldValue(date_sold_id, theRec.getFieldValue(date_modified_id));
When using a script, how can I assign the current date to a field? Thanks!
— Daniel
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hi,
I’m still trying to think of ideas to get from drafts app to Tap Forms.
I recently asked if the Tap Forms JavaScript had access to the clipboard (think of using that as the communications channel), but it hasn’t.
I am now wondering if it is possible to paste records into the iOS version? I could make a drafts action create the correct format for the paste.
Thanks
Martin
Brendan, I have one more question. The form.addNewRecord() function creates a new record but does not set any fields with default values specified. Eg I have a dateLeft field defaulting to today’s date; same with timeLeft defaulting to the time the new record is added.
Is there either a way to create a new record with all field defaults applied, or do this in the script? (I do not exactly know what the actual values of those TapForms date and time fields are, so I also do not know how to setFieldValue them…)
Hi y’all,
Am trying to use cloudant for syncing my database. Have followed the instruction re setting up an account, but I’m not sure where to find the password.
This is the alphabet soup I get from the “credentials” on the cloudant site:
{
“apikey”: “1ZQdMj162xdk3vf4N0ZMkQAhN4oikS2z5-xCd-SXAAIX”,
“iam_apikey_description”: “Auto generated apikey during resource-key operation for Instance – crn:v1:bluemix:public:cloudantnosqldb:eu-gb:a/6573add2f18f4d48b22620fd392dd094:32191e04-2a8b-4bbe-bc54-bff77190292f::”,
“iam_apikey_name”: “auto-generated-apikey-36ca775e-c28c-425c-bf55-4f5754841a8a”,
“iam_role_crn”: “crn:v1:bluemix:public:iam::::serviceRole:Manager”,
“iam_serviceid_crn”: “crn:v1:bluemix:public:iam-identity::a/6573add2f18f4d48b22620fd392dd094::serviceid:ServiceId-2432e2f3-f9ba-4cc1-be44-15a42d4bc426”,
“url”: “https://2dc42a4a-07a3-405f-91f6-66fbe35a4cdd-bluemix.cloudant.com”,
“username”: “2dc42a4a-07a3-405f-91f6-66fbe35a4cdd-bluemix”
}
The username is pretty apparent, but I have no idea what the password is. Can anyone help?
Many thanks in advance.
I created a mileage tracker form but posted it in the regular forum. Figured I should post it here for everyone to download. It requires Tap Forms 5.3 at a minimum because it uses JavaScript to copy the previous mileage value to a new record. You need to select a record and then run the script. Tap Forms will create a new record and copy over the values from the selected record to the new record.
Use the Import Tap Forms Archive function to import this file.
Thanks!
Brendan
Attachments:
You must be
logged in to view attached files.
Hi Brandon,
Cool! Didn’t think of that at all.
When I run it in the ‘edit script’ view, the result is shown in the Results field. I would expect to see this in the Title field in the Layout View too, but that remains empty.
Sorry for all the beginners questions!
Thanks!
– Daniel
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Yup. You’re right. I’ve just made a change to fix this so it will do what it’s supposed to do. The Mac version was just calling the wrong code that wasn’t evaluating the script only for those fields that were referenced in it. But the next update will behave that way.
Hi
I have the parent database “Photo Database” with the child “Photo Prints”. The child database is used to keep track of all prints created and sold. In there, I would like to include some basic information from the parent database such as image title.
In the parent database I set the one-to-many link and enabled show inverse relationship. Then in the child database I created a field with the type ‘script’ containing
var image_title = photo_database.getFieldValue('fld-a64a1b71aeb8408499143d9c852b0056');
image_title;
But when I run it, following error:
ReferenceError: Can't find variable: photo_database, column:33, line:1
I guess I’m missing something to define photo_database which is the parent “Photo Database”. Attached is the sample template. Thank you for your help!
– Daniel
Attachments:
You must be
logged in to view attached files.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I’ve done a bit more investigating.
In the script editor (on the Mac) after saving and then reopening it, there is a check mark against the A field and none of the others. So the script is doing the clever bit (knowing that it should only run on changes to A), but it appears to run on changes to any field.
I’m using Tap Forms 5.3.2 on the Mac.
I’ve now just checked on my iPad and iPhone and the script, correctly, only updates on changes to A. So perhaps it is a bug in the Mac version?
Thank you for that. I think I’m starting to get it.
To help my understanding I wrote this field script:
var a = record.getFieldValue(a_id);
record.setFieldValue(time_changed_id, Date.now());
document.saveAllChanges();
As expected, when I change the value of a, the time in milliseconds is shown in the other field.
So I added two more fields (and didn’t change the script). When I click between the two new fields (not editing them), the time in milliseconds is still getting updated.
I guess I should be doing something else to ensure the script only runs when a is changed. Could you point me in the right direction?
Thanks again.
Hi Martin,
It’s because when you use the record.getFieldValue()
call in a field script and click the Save button on the script, Tap Forms stores a list of field IDs that it references in that script separately on the Script field itself. Then when you change a value in one of those referenced fields, Tap Forms searches through all Script fields to see if that field being edited is referenced. If so, then it executes that script.
That’s how the example works. When you save the Script field, Tap Forms stores the ID of the barcode field being referenced. When you change the barcode value, Tap Forms finds the script that references that field and executes it. The code then fetches the JSON data from the URL specified along with the barcode value and then sets the other fields to contain the data parsed from the JSON response.
Hope that makes sense. It’s really quite a powerful feature.
Thanks!
Brendan
Thank you for that. That makes sense.
How does Tap Forms knows when any of the other fields the script references change?
eg. in the Tap Forms manual there is an example field script which fetches movie data when entering a value into a barcode field. How does Tap Forms know to only run this script when the bar code changes, as you wouldn’t want the api.upcitemdb.com call when the user changes another field.
Thanks
Martin