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,396 through 1,410 (of 3,011 total)
  • Author
    Search Results
  • #44173
    Sam Moffatt
    Participant

    Scripts are stored in the database and if you use CouchDB you can sync them with an external editor. I have a script sync tool which creates a backup of the script fields and form scripts in a CouchDB sync’d document (I think you might be able to run it using nearby sync as well but configuring that is a pain).

    I never put it out to the public but there was a version of the Script Manager that was done entirely via PHP and CouchDB that would push updates to the scripts back into Tap Forms documents. If you combined something that updates named script files with a tool like fswatch to handle updates when you hit save then you’d likely have the experience you’re after.

    #44171
    cf
    Participant

    I think Daniel’s suggestion to disable syntax highlighting for sufficiently large files is a good short term workaround. Having a way to edit the script directly with an external editor would be another option (assuming it’s saved as a file rather than a database record), being able to have a “show in finder” or “open in”, for example.

    cf
    Participant

    Hi Sam, I do have field scripts and when I get into a state where I am able to reproduce I did try to comment out all the code in the scripts to rule that out, crash still occurred. I agree this has the markings of a race condition though unlike a typical race condition once im able to get into a state where it’s reproducible its consistently reproducible with those records.

    Anyway I don’t want this crash to distract from the original issue I posted, which I think is much more serious and very eager to see a fix for.

    MiB
    Participant

    I have posted this 5 minutes ago, but it was marked as spam and is gone… Sorry if it pos up twice later.

    Im am subscribed to Sams youtube channel on which he is explaining things within tapforms, I wouldn’t have thought of before. (If you don’t know the channel, check it out, it is called pasamio.)
    Watching this channel, tought me, that much more things are possible. So I wonder, if it is possible to automate the things I am doing over and over again.
    If so, I would be happy to pay someone, helping me with that project, because I can’t code in Java Script (or any other language than a bit html and css).

    The task:
    Filling tapforms with audiobook metadata.

    The status quo:
    A simple database with one picture and some other fields. No links or anything fancy.
    Files on a Mac. In a directory called “x” All in this format:
    Directory named: “title [author]” or just “title”
    in there:
    one or more or rarely none “.m4b” files
    one or none “info.txt” file
    one or more “.jpg” file

    What goes where in tapforms:
    The part of the directory name “title” goes to a text field.
    The part of the directory name “author” goes to a text field.
    The length of all combined m4b files goes to a time field with hours / minutes
    The content of “info.txt” goes to a notes field
    The “.jpg” file goes to a photo field

    What is “automated” now:
    I do a copy and paste of the content of the whole directory “x” in a text file. Then I replace all ” [” with a “;” and all “]” with nothing.
    Then I import the text file into tapforms, so the “title” and “author” fields are filled.

    What would be the goal:
    Getting all mentioned above automatically into tapforms.
    – title: always there, so it should be inserted into the field in tapforms
    – author: could be empty. So not even the brackets are there. Not “title []”, but “title”. If so, the field in tapforms should be empty too
    – jpg: If one jpg is in the directory, it should be in the field. If more are in the directory, non should go to tapforms (I have to choose by hand)
    – length: the length of all m4b files should be added and put into the corresponding field. If no m4b file is in the directory, the field should be empty
    – info.txt: The content of this file should go into the notes field. If there is no info.txt, it should be empty.

    Importing title and author by hand is no problem at all. Getting the time in the field is the most work. Then info.txt and lastly the jpg.
    If these three things could be automated -or all five – it would be fantastic.

    Is it possible with not so much effort?

    Attachments:
    You must be logged in to view attached files.
    #44154

    In reply to: Open a Finder window

    raily74
    Participant

    Hi Brendan,
    Thank you for your quick response. Up until now I have always used the Attachment field and the Alias function. However, if there is only one folder in it, the field will take up too much space on the form for its usefulness. The little link is much smarter there.

    Hi Sam,
    you are my hero today! Thanks for pointing out the “script folder access”. A function that I did not know before. It also took quite a bit of Google research to understand what you mean by that. But in the end I solved it and I’m very happy with it. Many Thanks!

    Michael

    #44149
    Sam Moffatt
    Participant

    Cool that you used the Script Manager though that script is 440KB in size compressed. I can understand why the syntax highlighter died on it. When I unminified it, it came to 35402 lines and 1.4MB. It’s a chunky bit of Javascript.

    #44148

    In reply to: Open a Finder window

    Sam Moffatt
    Participant

    Try using the script folder access to give Tap Forms access to a location on your hard drive and then you should be able to point to it.

    Sam Moffatt
    Participant

    Do you have fields scripts that work on the record? There might be a data race with the layout renderer and something mutating the record state?

    cf
    Participant

    Here’s an example of a script that will cause this:

    https://raw.githubusercontent.com/cfilipov/tfscripts/master/cheerio.js

    You can try copy-pasting the contents of that script directly in the TapForms script editor and it will beach ball forever. It’s possible if I waited long enough whatever was blocking the main thread would finish but after waiting a long time I just killed tap forms (which of course does not save the script). If I had to guess it’s the syntax parsing of the js causing the hang.

    As a workaround I used Sam’s script manager to download the script and add it without using the editor UI. This works for getting the script in tap forms and it’s runnable, however, if you try to open the script to edit/view it will also hang just like before.

    #44139
    Sam Moffatt
    Participant

    You can hide the script field and it’ll keep working when ever it’s dependent fields are updated. Something simple to take out the +44 assuming it’s at the start of the field:

    record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/^\+44/, '').replace(/[^0-9]/g, '');
    

    The ^\+44 basically says match the start of the string (the ^ character), match a plus sign (the \+ piece, + has special meaning normally so needs to be escaped) and then match “44”. If the +44 isn’t at the start then remove the ^ character (e.g. /\+44/) to just replace that string.

    I chain this as two replace statements just because it makes things a little clearer what is going on (e.g. you’re getting the field value, then you’re replacing the country code and then you’re making everything a number).

    Regex 101 link: https://regex101.com/r/hPF4kb/1

    Regular expressions can be a bit of a challenge to learn but if you’re doing string manipulation they’re an invaluable tool in many languages, including Javascript!

    #44138
    Andrew Drapper
    Participant

    Thank you so much.

    Works like a dream. I could fight on trying to parse the off +44 that some records have, but I think I will just hand modify as they come up.

    Presumably, I now hide the script field and let it do its stuff in the background?

    Andrew

    #44132
    Andrew Drapper
    Participant

    Sorry,

    I probably need to do a bit more reading into the manual but I now have

    function SMS() {
    
    	var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, '');
    	 	
    	var SMS = mobilephone + "@textmagic.com";
    	//console.log(SMS);
    	
    	return SMS;
    
    	const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d';
    	record.setFieldValue(email_id, SMS());
    	document.saveAllChanges();
    	
    
    }
    
    SMS();

    But though I do get a nice “07***726@textmagic.com” in my SMS Script field, it does not place anything in the email field.

    #44128
    Andrew Drapper
    Participant

    With some fiddling, I got this to work

    function SMS() {
    
    	var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); 	
    	var SMS = mobilephone + "@textmagic.com";
    	console.log(SMS);
    	
    	return SMS;
    
    }
    
    SMS();

    But I now have this number in a script field and therefore can not click on the send email symbol.

    Can I now past this value into an email field?

    #44122

    In reply to: Scripts and searching

    Sam Moffatt
    Participant

    When you’re using a JOIN field, both sides are M:M relationships because it doesn’t know if it is singular or not. The calculation field there can’t handle the M:M relationship properly in the same way it it can being on the child side of the 1:M where there is only one entry. The solution for that is generally a script that just pulls out the first entry from the field.

    I use this construct to gather all of the child entries and join them together:

    var client_contact_details = record.getFieldValue('fld-beaf858dba7d4014b89722411ebcbd3f');
    if (client_contact_details) {
    	client_contact_details.map(r => r.getFieldValue('fld-0d5ab10b7374418bac721d6446c81b73')).join(' ');
    }

    First line gets the child records from the link to form, second line checks if we got a value back (avoid undefined error, mostly harmless but some defensiveness doesn’t hurt), the third line is a little bit to unpack though. The map function is like a short hand of a for loop to run a single function. In this case we’re going through each of the records in client_contact_details and “mapping” that value (a Tap Forms record) to the value of the field fld-0d5ab10b7374418bac721d6446c81b73. The last part of that line basically says to convert the array to be “joined” by spaces.

    For the JOIN count for documents, I did COUNT( Notarised documents - Join::Type of document ) and that seemed to work properly for me giving me a count of two.

    Sam Moffatt
    Participant

    Don’t know why it works if you comment out the variables it works. Again I copied and pasted from the website and it worked fine for me so certainly weird. Though I generally try to put the variables at the top of the script personally, a force of habit from QBASIC many moons ago.

    Also odd that you get a crash with the async await there, hopefully Brendan gets the stack dump and can see what went wrong there. I’m paranoid about saving things (too many bad experiences with Word 95) so I frequently save things though on the mobile devices it’s a little harder.

Viewing 15 results - 1,396 through 1,410 (of 3,011 total)