Hi Folks,
after several days playing with scripts (I love it) I have 3 another questions:
1. How to write in an existing recordset in another form ?
Adding a recordset works:
var doc=document.getFormNamed('Test2');
var newRecord = doc.addNewRecord();
I would like to modify an existing field in a known recordset (I have the ID of the recordset and the field).
Additional: Would it be possible to search for a value and modify it in another form ?
2. Is there a possibility to enable and customize a reminder in a date/time field ?
3. is it possible to format text in a memo field (bold, font, size, color …) ?
From the documentation:
Please note that the field IDs in the above script (e.g. movie_title_id = ‘fld-….’) are unique to the form this script was written for. You would need to use your own field IDs from your own form to make this script work.
You create them inside the script editor by selecting the field and then clicking on the ID button.
Brendan, it might be helpful to update the screen captures of the script editor as well to show all the buttons available right now.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Excellent suggestion. I probably wrote that script before I defaulted to appending “_id” to the field titles.
I’ve just updated the manual.
Those are the field identifiers in your form. It would be better if the variable names in this example code ended with ‘_id’ as they do when you create them in the script editor,
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Well, I get the theory of what you suggest (I think) but I have never tried my hand at javascript coding ever e.g. I haven’t a clue what an ‘array’ is. But I shall look into it tomorrow and follow the link Brendan gave for help with javascript coding. Thanks for the advice. P
I had a similar problem the other day. These are the steps I would use:
1) Import your data into a form called “election results”.
2) Create a second form called “constituencies”. Then create a form script that makes an array that contains each constituency only once. Using a javascript set object makes this very easy. Then have this script create new records in constituencies, one per constituency. Once done, you can delete this form as it is no longer needed.
3) Link the two forms together using the ‘join’ link type on the constituency field. Now the two forms are linked. Enable Show Inverse Relationship.
4) In the “constituencies” form, you now can do your analysis where you count the number of votes each party got etc. Thanks to the linked forms, you can easily loop over all matching records in the child form and add the votes per party. For this analysis you would have a bunch of record scripts that do the work for you.
Hope this gives you an idea how this could be done. Happy coding!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Check out the JavaScript API page: https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
If you have a named search then you can get that via form.getSearchNamed('Search Name') and then you can call getRecords() on what it returns to you.
Ya, got it.
I already created a bunch of helpful scripts,
I only was stuck hanging to automate with a script field rather than execute it manually.
One last question:
Is there a possibility to get filtered recordsets only ?
This returns ALL records:
var records=form.getRecords();
Daniel-san.
Thank you for your code.
I just wanted it.
I will include the code in my scripts.
Thank you again.
The XML file is rather simple so I just tried a little hack to parse it and extract the data you are looking for:
function getText(str, tag){
return str.substring(str.indexOf('<'+tag+'>')+tag.length+2, str.indexOf('</'+tag+'>'))
}
function parseIsbnRecord(url){
var xml = Utils.getTextFromUrl(url);
// cleanup xml
xml = xml.replace(/dc:/g,'').replace(/</g,'<').replace(/>/g,'>');
// extract recordData section
xml = xml.substring(xml.indexOf('<recordData>')+12, xml.indexOf('</recordData>'))
var data = [];
data['title'] = getText(xml, 'title');
data['creator'] = getText(xml, 'creator');
data['language'] = getText(xml, 'language');
data['publisher'] = getText(xml, 'publisher');
data['description'] = xml.match(/<description>([^<]+?)<\/description>/g);
for (n=0; n<data['description'].length; n++){
data['description'][n] = data['description'][n].replace(/<description>/g, '').replace(/<\/description>/g, '');
}
return data;
}
var url = 'https://iss.ndl.go.jp/api/sru?operation=searchRetrieve&query=isbn=9784334779146';
isbn_record = parseIsbnRecord(url);
console.log("Title: " + isbn_record['title']);
console.log("Creator: " + isbn_record['creator']);
console.log("Publisher: " + isbn_record['publisher']);
console.log("Language: " + isbn_record['language']);
console.log("Description: " + isbn_record['description']);
This generates following output:
Title: まよい道 : 新・吉原裏同心抄(一)
Creator: 佐伯泰英 著・文・その他
Publisher: 光文社
Language: jpn
Description: 判型 : 文庫,販売対象 : 一般,発行形態 : 文庫,内容 : 日本文学小説・物語,Cコード : 0193,ジャンル : 文庫
This code is very specific to this example ISBN number you provided. Most likey, other entries are very similar.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
XML is hard because inherently the structure doesn’t easily map to a JavaScript object unlike JSON which is technically JavaScript. I looked for a JS native XML option but most seemed to suggest using the browser based DOM handlers which doesn’t work for Tap Forms and Apple’s JavaScriptCore.
What makes XML a challenge is that a single node in XML can have attributes as well as a value on top of being a nested structure as well which may have child values whose ordering is important but whose values is duplicated. Part of the heritage coming from SGML similar to the challenge with HTML.
For myself I have a set of PHP scripts that I use to bridge and give Tap Forms a JSON interface to work with. I use these for scraping web sites and converting values so that Tap Forms can work with a relatively clean JSON interface and the PHP scripts do the heavy lifting. This does mean you need to run a web server or similar service somewhere to make it work but it could help convert the XML into domain specific JSON for Tap Forms to consume.
No worries, happy to help! The Calculation field is pretty powerful, it has a bunch of built in functions for simple operations from the fx menu item.
The script field is a bit tricky however you can press the “play” button in the editor above the keyboard and it’ll run the script for you and you can see it’s output. There is also an option for a console log as well to see any debugging output. That enables you to do some iteration and testing as you go.

Attachments:
You must be
logged in to view attached files.
I was (not yet) aware about the fx in a calculation field, using version 5 since some days.
Refresh the recordset to get a value from a script field is tricky.
Thanks, Sam.
Calculation field exists on iOS, all of the field types are supported on both Mac and iOS. There’s a slight difference that on iOS it wraps the field name in square brackets so it’d look like `DAYS(
[Bought];TODAY())` or similar.



To your question:
1. That should return Hello
2. Script is triggered when a dependent field is changed or you refresh the field. On iOS, pull the record down to refresh the calculation manually.

Looking at your screenshot, you’re still missing the return statement at the end. You can do return days; as the last line of the method similar to the return 'Hello'; and it should work properly.
Attachments:
You must be
logged in to view attached files.
Hello, I’m a elder Tap Forms beginner.
Basically, I am using Tap Forms for manage of books.
Now, I am trying to write scripts for get books information from National Diet Library, Japan. Its output is XML format.
So, I need XML parsing, But I have no ideas to parse it. If Tap Forms Utils has utils.getXMLFromUrl() like a utils.getJSONUrl() or utils.getTextUrl(), it is useful.
Now, I am getting data using utils.getTextUrl() from site. and trying to parse XML data. I know there is XML parser in DOM. But I don’t know how to use it . The pioneers of Tap Forms Scripts, Would you please advice me good solution.
Regards. Kenji.