Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1,231 through 1,245 (of 2,989 total)
  • Author
    Search Results
  • #45119
    Daniel Leu
    Participant

    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

    #45118
    Konrad Schoettl
    Participant

    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

    #45107
    Sam Moffatt
    Participant

    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 :)

    #45040
    Sam Moffatt
    Participant

    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 :)

    #45017
    Sam Moffatt
    Participant

    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.

    #45012
    Sam Moffatt
    Participant

    Great to hear you got it to work and that the Script Manager stuff was helpful for you as well :)

    #45007
    Tom Kerswill
    Participant

    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

    #45006
    Tom Kerswill
    Participant

    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

    #44967
    Brendan
    Keymaster

    And with setting the Script Folder on the Preferences screen, you can put your data in there and then use var data = Utils.getTextFromUrl(url); command to read in the file. Then parse it. The split() function could be used to split the lines into an array of lines. Then for each line, use split again to split by the column delimiter. But it really depends on how your data is structured. If you have delimiters within your content and quoted content, then that would be much more difficult to deal with. I should add a JavaScript API for parsing delimited content into two dimensional arrays of data, basically giving you access to the code I already use for parsing CSV files.

    #44938
    Daniel Leu
    Participant

    I don’t see an API for that. In one of my applications, I use the clipboard to import data into TF. It took a bit of time to get the data parsing right, but now it works well.

    If your data is already in CSV format, the parsing should be easy. I don’t think that such a script is that difficult since you already know where the data should go. You then call the script with tapformz://script/[document ID]/[form ID]/[form script name]?key1=value1&key2=value2...

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #44934
    Tom Kerswill
    Participant

    Hi

    Is it possible to import data programatically? Ideally by using an existing import preset?

    I’d like to have something like Hazel or Keyboard Maestro trigger this when data in a file changes, so that I can reimport it into Tap Forms.

    I suspect I could probably do a form script that might do this; but ideally it would be able to trigger Tap Forms’ existing import system, as it can then do things like automatically setting links to other forms, etc., whereas I suspect this would be quite complex to do if building an import script from scratch.

    Thanks in advance,

    Tom

    #44915
    Sam Moffatt
    Participant

    You can use a script to get the children of one Link to Form field of JOIN type and then add them to another Link to Form field. In terms of script, a form script like this should do the trick:

    record.getFieldValue('fld-joinfieldid').forEach(rec => record.addRecordToField(rec, 'fld-1tomanyfieldid'));
    

    You could expand it to run on all of the records in your form but this will do just the currently selected record. I haven’t tested it but it should work.

    #44910
    Aaron Greenhouse
    Participant

    With regards to the import problem, I was importing into a new empty document.

    The problem I have with the Join Link type is that I created a new database for purchases and items after date X, and in that database I have used the 1 to many link type and set the links explicitly. I would like to import my old data from the spreadsheet (from before date X) into the new database. I cannot have both JOIN and 1-to-Many for the same field. I suppose I could have two fields, “Purchase” and “Legacy Purchase.” I could live with that. Is there a way, perhaps using a script, to copy the references from a “JOIN link” field to a 1-to-Many field?

    #44902
    Sam Moffatt
    Participant

    The other two numbers round correctly to the right value:

    0.5600000000000001
    0.560000000000000053290705182007513940334320068359375
    0.5500000000000000444089209850062616169452667236328125
    0.56999999999999995115018691649311222136020660400390625
    

    The script field is probably the answer if you really want to fix it, I don’t think there is a way within a calc field you can make it work when embedded in a string like that.

    #44882
    Sam Moffatt
    Participant

    What is the type of current year rate? I was trying to figure out how to repro this to figure out a viable solution but I didn’t see one. I create a number field and populated it with 0.56 and the text calculation field printed .56 as the rate as I’d expect. I tried doing it as a calculation field with 56/100 but that didn’t seem to trigger the weird behaviour either.

    What you’re seeing is floating point rounding errors. The 0.56 ends up being stored as 0.560000000000000053290705182007513940334320068359375 which is why you see 0.5600000000000001 as the 5 rounds up:

    0.5600000000000001
    0.560000000000000053290705182007513940334320068359375
    

    I suspect this is a reflection of the underlying JSON data model (Javascript floating point numbers are IEEE-754 64-bit double precision numbers) and unfortunately leaking out. For some more gory details I found a YouTube video on floating point representation and rounding error and an online converter that lets you put in 0.56 and see what the computer is doing.

    I have an sprintf implementation that I ported for printing formatted strings in Javascript that should handle it if you want, there was a not dissimilar thread on if to use a calc or script field that shows formatting floating point numbers. That may yet be the solution for you as well but it’s a bit heavier than a simple calc field.

Viewing 15 results - 1,231 through 1,245 (of 2,989 total)