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,386 through 2,400 (of 2,950 total)
  • Author
    Search Results
  • #36630
    john cesta
    Participant

    Will the movie script work on the iPad mini tap forms?

    I wasn’t sure if it’s only for the Mac.

    If it works on the mini I’ll putt with it.

    #36625
    Michael Harding
    Participant

    Hmmm. Actually, I think I must have scripted those equations initially in Bento, which explains perhaps why I didn’t recall scripting the IFEMPTY commands…

    #36613
    Brendan
    Keymaster

    Hi John,

    Not at the moment. But in the next update I’ve added a method called record.setRecordColor() which would let you do that by giving it a web colour in hex format. E.g. record.setRecordColor('#FF00CC'); It requires you use the Scripting engine though.

    Here’s an example I just tested:

    function Record_Colour_Script() {
    
    	var number = record.getFieldValue('fld-046db84197fd44a6adf50b3a9ab426d5');
    	var colourHex = '#005090';
    	if (number > 20) {
    		colourHex = '#c59';	
    	} else if (number == undefined) {
    		colourHex = 'CLEAR';
    	}
    	record.setRecordColor(colourHex);
    
    	form.saveAllChanges();
    	
    
    }
    
    Record_Colour_Script();

    It won’t work yet in the production Tap Forms version. But it will in the next update.

    #36610
    Sam Moffatt
    Participant

    The Utils.getJsonFromUrl() returns a JavaScript object directly. You don’t need to parse the JSON file, Tap Forms does that for you and creates a nested set of Javascript dictionaries and arrays.

    The Google Books API response is a little convoluted, what you want is a few levels deep. You might want to look into grabbing a JSON formatter for your favourite web browser to help see the layering in the responses with a tree format.

    Here’s something simple to get you further along:

    function Json_Request() {
    	let data = Utils.getJsonFromUrl('https://www.googleapis.com/books/v1/volumes?q=isbn:9780061143397');
    	console.log(data['kind']);
    	for (let i = 0; i < data['items'].length; i++)
    	{
    		let item = data['items'];
    		let volume = item['volumeInfo'];
    
    		console.log('Title: ' + volume['title']);
    		console.log('Print Type: ' + volume['printType']);
    		console.log('Authors: ' + volume['authors'].join(', '));
    	}
    }
    
    Json_Request();
    

    This is a form script I started, it’s intended to run from the editor and use the console to log out the data. You’d need to update it and change it to do what you want.

    EDIT: Ok, I think I understand where you might have gotten stuck.

    Javascript lets you use array syntax (e.g. the square brackets) to access dictionaries, arrays and also strings. To access a dictionary, you use a key lookup (e.g. data['items']); to access an array, you generally use numeric lookups (e.g. results[0]) and you can also access a string and it will give you the character at that offset.

    Quick example of the string output using a form script as a vehicle:

    var mystring = 'Test';
    for (var i = 0; i < mystring.length; i++)
    {
    	console.log(mystring);
    }
    

    Will output the following in the console:

    T
    e
    s
    t

    Because it’s treating the string as an array of characters instead of giving you an error. I get caught by this from time to time and it sometimes takes me a moment to realise what I’ve done.

    If you find yourself hitting this then you’re probably iterating over a string instead of the array you were intending. Hopefully this helps.

    #36602
    Mark
    Participant

    Thanks for your response – it helped me realize that I don’t know how to parse through a JSON array and/or nested arrays.

    In playing with my script, I seem to be able to read one character at a time.

    I’ve tried looking at some tutorials, etc. but they seem to use functions not available within Tap Forms scripting. Could you provide a simple example or point me to one so I can learn?

    This is a really powerful feature that I’d like to be able to use.

    Thanks again,
    Mark

    #36599
    Brendan
    Keymaster

    @Mark, can you post your script?

    That’s a JSON result, so it should work to parse as long as you parse it right. Note that items is an array, so you’d have to get that and then loop through those items and pick out any data you need.

    Basically it’s just recognizing what returned elements represent an array [ ... ] and what elements represent a dictionary { ... } and get the values appropriately.

    #36594
    Mark
    Participant

    Hi – I’m trying to copy your approach on this VIN script to pull book details from Google Books API, but the data I can’t get the resulting data to parse the way this script works with the NHTSA data.

    here’s a sample URL
    https://www.googleapis.com/books/v1/volumes?q=isbn:9780061143397

    Where you refer to ‘Results’ in the NHTSA data, I’ve tried ‘item’ ‘kind’ etc. but it does not seem to recognize the data structure.

    I have a feeling I’m missing some detail about how to access the data’s structure.

    Thanks for any insight,
    Regards,
    Mark

    #36576
    Sam Moffatt
    Participant

    You’ll need to create a new web site field to put the data into. Then your script just needs to know what that field ID is and then set it:

    form.runScriptNamed('vlookup');
    
    var trello_cards_id = 'fld-a6346935a6af40d1833fad4f49958bca';
    var tsm_rfs_id = 'fld-b0c9111f87064a23bde75c965374e97c';
    var short_url_id = 'fld-7888517ad8204f5aa7a4bf926c92be15';
    var website_id = 'fld-yourfieldhere';
    
    var rfs = record.getFieldValue('fld-e13aa1493c6f4b919f30b27cd8bc8ae9');
    
    var website = vlookup(rfs, trello_cards_id, tsm_rfs_id, short_url_id);
    record.setFieldValue(website_id, website);
    website;
    

    Something like that should work, hopefully it makes sense. website_id is the new field you add to store the URL and make clickable, I put website into a variable so that I can use it to set and then use it as the return value for the script (kinda redundant but not harmful). You could probably hide the script field once it’s all working.

    EDIT: Updated to remove smart quotes. If you have smart quotes, things won’t work the way you expect and you’ll get errors from JavaScript. If you’re working on iOS, make sure you use the quote button above the keyboard to ensure you don’t put in smart quotes accidentally. On the Mac, it usually doesn’t input smart quotes so you’re safe there.

    #36575
    matt coxon
    Participant

    Hi Sam, thanks very much for the response, I understand what you mean but can’t seem to get the syntax correct

    Do I add the command to the main script field after the vlookup or in a new script field I played around with various but can’t seem to get it to work, but when I do I’ll need to apply it to date fields in the same scenario as the web field so will be very useful

    Thanks

    #36555
    Sam Moffatt
    Participant

    You can load the attachment up into your existing document, alternatively you can get this script, create a new form script and update the field ID’s at the top to match your field IDs. On Tap Forms 5.3 or later, form scripts are a third tab next to form and field settings.

    #36532
    namor
    Participant

    dear brendan

    thanks a lot! i could add the fields together easily
    but i could find out yet how to hide the field in the form.

    i have some other fields that i would like to hide as
    an ascending number i use for a calculation that doesn’t
    have to show up.

    is there a simple script?

    best, roman

    #36523
    Sam Moffatt
    Participant

    You can do the same on the iOS version as on the Mac, in the calculation editor you need to use [Field Name] instead of clicking on the fields and also you need to make sure you use the quote button above the keyboard to avoid inserting smart quotes.

    The examples above in the iOS calculation editor would be CONCAT([First Name];" ";[Last Name]) and CONCAT([Street];" ";[City];" ";[State]).

    Doing the script example on iOS is a few extra taps to select the fields but not that bad. I prefer script fields because of the better error reporting and testability (just click the “run” button to see if the field will work; make sure you’re on a record first though or you’ll get an error that record isn’t defined or similar). I wouldn’t want to do a lot of script or calculation field work on iPhone but on the iPad it isn’t too bad if you have a full keyboard. I’ve written some pretty crazy stuff on the phone but doing it on the desktop and using P2P sync or CouchDB sync is much easier.

    Attached is a video of doing a new script field on my iPhone in one of my test databases, reordering it to make sure it’s the first and then going to the list view on the phone.

    Attachments:
    You must be logged in to view attached files.
    #36522
    Sam Moffatt
    Participant

    You can’t make a script field clickable (would be nice, it’s on my wish list*) however as a workaround what you can do is use the script field to set the value of a web site field using record.setFieldValue(field_id, value). Then when the script is run, it’ll update the web site field to be the new value which means you can then click on that field to open the link.

    * I’d actually like a way of being able to define a custom icon for a script field and an action handler distinct from value. I think it’d be cool to have the ability to have the script field display one value but when you click it, it opens up a link or perhaps even runs a form script with a field context set. Doing all of that and getting it right is a lot of work and perhaps a little too powerful.

    #36520
    Sam Moffatt
    Participant

    Try something like this:

    var address_id = 'fld-fb97220d3a4a4df48df4a54030766c54';
    
    record.getFieldValue(address_id).match(/Cupertino/) ? 'Yes' : 'No';
    

    You can use the method match on strings, it takes a regular expression which is why the string is in backslashes not quotes. I use a ternary operator to take the output of the match and do a ‘yes’ or ‘no’ based on if something was found.

    W3C Schools page for match: https://www.w3schools.com/jsref/jsref_match.asp (has links for further details on regular expressions)
    Mozilla page on ternary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

    #36515
    Sam Moffatt
    Participant

    Create a new calculation field, in the form options you can set it up. Here’s a quick recording of how do that with a calculation field.

    Looks like I hit a bug/quirk that commas, even in the quoted strings, seem to trigger something. That one’s for Brendan to look at.

    To work around that, I also did a similar example using a script field. It’s a little more verbose but I find the script fields easier to work with than the calculation fields because it has better error reporting (easier to know what you did wrong). That’s probably less likely if you don’t learn JavaScript but there are plenty of resources on the web to learn JavaScript.

    As you can see, both of the calculation fields update the list view on the left to display the composite data. Hopefully this helps!

    Edit: Had to trim the calculation field recording to get it to fit under the file size limit. I attached a screenshot of what the final calculation that worked looked like (I ended up doing some experimenting with field separators).

    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 2,386 through 2,400 (of 2,950 total)