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 - 2,341 through 2,355 (of 2,986 total)
  • Author
    Search Results
  • #37136
    Daniel Leu
    Participant

    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

    #37120
    patrick powell
    Participant

    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

    #37119
    Daniel Leu
    Participant

    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

    #37104
    Sam Moffatt
    Participant

    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.

    #37102
    Marcus
    Participant

    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();

    #37101
    Kenji Sugimoto
    Participant

    Daniel-san.
    Thank you for your code.
    I just wanted it.
    I will include the code in my scripts.
    Thank you again.

    #37099
    Daniel Leu
    Participant

    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

    #37093
    Sam Moffatt
    Participant

    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.

    #37081
    Sam Moffatt
    Participant

    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.
    #37079
    Marcus
    Participant

    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.

    #37072
    Sam Moffatt
    Participant

    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.
    #37071
    Kenji Sugimoto
    Participant

    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.

    #37070
    patrick powell
    Participant

    This was so long ago I can’t remember. I was still using OS9 it was that long ago. I don’t know why Apple ditched the database function when the introduced their iWorks suite, but they did. I bought Tap Forms at the beginning of the year to create a database (and did so, a very, very simple one) and I really haven’t spent a great deal of time getting to know it and its features. So, no, I have no screenshots.

    I mentioned that I wanted to get a rough idea of how a general election would turn out given a certain likely swing and that is what I want to do again. Brendan has mentioned javascript (with which I am not at all familiar but I will check it out) so I shall see how I get on.

    I would be surprised if Tap Forms didn’t have a ‘visual’ feature because when I was looking up an alternative to Appleworks database (and not wanting to spend a million on Filemaker) Tap Forms seemed to be getting most of the thumbs-up.

    #37068
    Marcus
    Participant

    Hi Guys,

    thanks so far, but I‘m not sure if we‘re talking about the same.

    @Sam: This Built-In calculation field is not available on an iPhone !
    I do not have this TypeError like you.

    My screenshot shows a working method,
    but I‘ve to use a script field and additional a „days“ field. What I‘d like to know if only a script field would be necessary to return the value ?

    However, independent of the calculation of days,
    that‘s a general question:

    Assuming I have a simple script field:

    function Script() {
    return 'Hello';
    }
    Script();

    1. shouldn’t the field value „Hello“ ?
    2. when a script is triggered ?

    Attachments:
    You must be logged in to view attached files.
    #37064
    Brendan
    Keymaster

    Hi Patrick,

    It sounds to me like what you would need is a Script field to do your if/then function. How’s your JavaScript? :)

    You can create custom layouts in Tap Forms for Mac and colour your fields and values as you like.

    The online user manual will have all that you need to know to get started with scripting in Tap Forms and for customizing layouts. You can access the manual from the Help menu.

    Or click here for Scripting: https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    and here for layouts: https://www.tapforms.com/help-mac/5.3/en/topic/layouts

    Thanks!

    Brendan

Viewing 15 results - 2,341 through 2,355 (of 2,986 total)