Hi,
being someone who doesn’t know Java Script, I have been trying to copy three fields and place them into a fourth field, which is a different field to where the script will reside. As it is Street, Suburb and State that I want copied I also need spaces between the three fields, so when pasted into the “Map location Address” it will return the google map location of the address. I’ve attached the relevant part of the form to hopefully make it clear what I am trying to do. I couldn’t find my question in the forum, so if it has has been covered previously, I apologies in advance.
Cheers
Trusty
Attachments:
You must be
logged in to view attached files.
Time field stores time in seconds (maybe milliseconds?) of the time since midnight of epoch, it’s in a sense a date/time field with a fixed date. It’s likely not a great use case for you here if your aim is data export. It’d be usable but you’d need to do some post processing on it.
In terms of managing this, I’d just have two fields, one for the action name (using a combo box picklist probably) and a second number field for the time duration in minutes. That should let you fill in your own action name and then the number field being duration in minutes can be set to what ever value you want. In terms of automation, I’d go towards having a script field which then sets the number field to the known values. Essentially you need to map the string value you set to a number and at the moment this is likely the easiest way:
function Fill_Duration() {
var action = record.getFieldValue('fld-4807f45c4fd9403c8beef5edce917c6d');
switch(action) {
case "Action A":
record.setFieldValue('fld-4b64c978546045ab944ea4c959d89953', 5);
break;
case "Action B":
record.setFieldValue('fld-4b64c978546045ab944ea4c959d89953', 10);
break;
case "Action C":
record.setFieldValue('fld-4b64c978546045ab944ea4c959d89953', 20);
break;
}
document.saveAllChanges();
}
Fill_Duration();
In my sample form, fld-4807f45c4fd9403c8beef5edce917c6d is the “Action” text field with combobox pick list and fld-4b64c978546045ab944ea4c959d89953 is my number field. I’d hide the script field because it doesn’t need to be visible. Then when you export the records to CSV, you’ll have a field with the name and a field with the duration, both of which you can override with custom values.
I’ve attached a quick form I did handling this, you should be able to do the same by replacing the form ID’s with the ones for your fields (either visible in the field editor underneath the description field or you can get it in the script editor by clicking “ID”).
Attachments:
You must be
logged in to view attached files.
Make sure you tick “show inverse relationship” to also have a Link From Form field created in the linked form as well.
Once you have a JOIN field up and running using two common fields between the records, you can use a script to copy the links from the JOIN field to your other 1:M Link to Form field.
I did try that after Daniel posted that comment. However I can’t get the refresh to do anything (I’ve pulled down a long way and nothing happens – see attached screenshot)
However, I have quit TapForms while the saved search is active, which means it is on when I return to that table, and it doesn’t show the script added 4 or 5 stars.
I could send a cut down example database if that would help.
Thanks
Martin
Attachments:
You must be
logged in to view attached files.
Thank you for replying.
The saved search was set up months ago. The record was added using a script since then, and the phone has been rebooted (over the weeks) since it was added, but it still doesn’t appear.
I should say I am using Tapforms on my iPhone and iPad and even when the record is synced (using iCloud) it doesn’t appear on either device.
Hope you can help,
Martin
Hi,
I’m setting a star rating when I add a new record using a script.
When I do this the field value shows the correct number of stars in Tapforms – however if I create a search and query on, eg rating is 4, then the programmatically set four star records do not appear.
Any records entered manually do appear and if I change the rating of my scripted 4 stars, to another rating then change them back to four, they do filter correctly.
It just seems when they are set programmatically they don’t filter correctly.
I am using record.setFieldValue() to set the rating.
Can anyone tell me how I should be setting the rating so that the query works?
Thanks
Martin
Another option is to use a tapformz url:
Utils.openUrl('tapformz://script/db-xxxx/frm-xxxx/ScriptName?option1=A&option2=B')
This way you can directly call the script with the given parameters.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
The script you are calling should just define a function or several functions. So you don’t call the function at the end of the script that you usually would in a form or field script. Once the runScriptNamed() was executed, you would call the function in question with the given parameters.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I have defined a form script that is called via ‘runScriptNamed()’ twice from different field scripts. This is basically working. An example: I have a form for all persons (authors, translators, actors, …). Within this form, I have fields for the date of birth and death. As sometimes only the year is known, in both cases I have defined separate fields for day / month / year. As for the month, there is a picklist with options ‘january, february, …). Now there is a script field which stores the person‘s name along with the dates of birth and death, for example ‘Wells, H. G. (21.09.1866 – 13.08.1946)’. To get this, a form script converts the month (september) to a numeric like text (09). This is done for birth and death.
Now the problem: It seems there is no way to call the form script (‘runScriptNamed’) with parameters?
I found a solution by using global variables, which works, but perhaps there is another (perhaps better) solution?
Thanks for any ideas or hints!
Konrad
If you’ve not seen it, there is the concept of database normalisation which is the process of thinking about your fields and structuring the database. I will say that you might for various reasons want to replicate fields and the cool thing is that calc and script fields can help you copy data without having to manually maintain them.
Good luck mapping it all out :)
I think it’s more up to personal preference. If you want to add notes per variety that you plant or extra metadata specific to that day and variety, then you might want to use a record per day per variety. You could do a record per day and then use the link to select which varieties you planted that day. If you don’t track any other metadata with your planting then a single record per day might work (maybe a free form notes field).
If you did per day per variety then you want to do a 1:M relationship and enable “show inverse relationship” checkbox on the Link to Form field then it will create a Link From Form field. On the Link From Form field, there should be four buttons: the first is an add button (it will create a new record and take you to the form), second is an unlink button, third takes you to the linked record and the fourth lets you select a new record. If you click the first button to add a new record, you can populate it from that screen and then jump back to the previous record with the back button that should appear at the top of the record next to the default layout selector. When you jump back it should have that linked already.
If you wanted to do one per day then I’d do a M:M relationship it’s a similar process though you get a table view on both sides when you enable the “show inverse relationship”. It’s a little easier to do data entry with the tables for new records because you can do that inline or you can create a record and go directly to it (second option under table) to fill it in.
In general you don’t need a primary key in the traditional database sense mostly because internally Tap Forms has unique identifiers, you only really need it for your own purposes. You can use calc or script fields to help you compact multiple fields into a single field to make it easier to pick out of the record selector.
One other random thought is that if you only have a name for the variety and no other metadata, you might want to look either using autocomplete for it or at a pick list for it. Autocomplete does what it says on the tin and pick lists can be configured to refer to a particular field so you can get a sort of autocomplete that way. Pick lists have slightly more UI options and you can also do stuff like record highlighting with them.
If you can take a short video and upload it to YT then you can link to it. If it’s quick enough and a small enough window area then it’ll fit into the file upload limit for the site. You might have found a bug in the system which would be a cool win as well :)
By default the export defaults to exporting all records in a form but if you have a saved search you can use that to limit the scope. A method would be to create a check mark field that flags a record for export and then a saved search on that field. Then with that saved search selected, you can use File > Export > Records to get a CSV/XLSX with just those records (or a single one).
You could write a form script to put data onto the pasteboard in what format you want. A little more effort but more flexible. If you have a web service, you can send the data to a web service via POST request. If you ran a local server, you could use that to write locally.
Great to hear you got it to work and that the Script Manager stuff was helpful for you as well :)
Hi
I’m programmatically creating fields using:
form.addNewFieldNamedWithType(key,fieldType)
The documentation for that function in the scripting API gives the following field types:
[text, number, calc, location, photo]
I’d like to add a boolean / checkmark / yes-no field.
Is this possible using a script?
Tom
Thanks so much for the help. I ended up writing something based on your great Script Manager, Sam, and then building out something to automatically add the fields (if they’re not already there).
It works really well. Hooking into the existing CSV / Json import would be lovely; but doing it with a script isn’t too bad in the end.
Here’s the snippet:
let targetRecord = getRecordFromFormWithKey(form.name,indexKeyId, rowId);
if (!targetRecord) {
console.log("Adding new record...");
targetRecord = form.addNewRecord();
}
console.log("Record: " + targetRecord.getId());
for (const [key, value] of Object.entries(row)) {
let keyField = form.getFieldNamed(key);
if (!keyField) {
console.log("Adding field: " + key + "Type: " + typeof(value));
if (typeof(value) == "number") {
fieldType = "number";
}
else {
fieldType = "text"
}
keyField = form.addNewFieldNamedWithType(key,fieldType);
form.saveAllChanges();
}
keyId = keyField.getId();
console.log("Key: " + key + " keyId: " + keyId + " Value: " + value);
targetRecord.setFieldValue(keyId, value);
}
Tom