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,261 through 1,275 (of 2,952 total)
  • Author
    Search Results
  • #44545
    robinsiebler
    Participant

    Is there a way to disable the pop up dialog when you run a script?

    #44543
    robinsiebler
    Participant

    Ok, now I have my basic document/form/script. It runs (Yay!). But when I try to trigger it from a Siri Shortcut, nothing happens and then I get an error saying it too too long to run…

    Attachments:
    You must be logged in to view attached files.
    #44540
    Nighthawk
    Participant

    If you get to the point where you want to give up on using TF to create your shopping list, you might want to look at the app ‘AnyList’ (https://www.anylist.com). I’ve used TF for many things but I never got into scripting, so I ran into trouble trying to build my own TF shopping list. I tried AnyList and liked the free version enough to pay the $10 annual fee. Although it can handle meal planning and recipes, I only use it for lists. BTW, it’s also great for ‘To Do’ lists. The best part is that there is a web interface, a Mac app, an iOS app (both iPhone and iPad), an Apple Watch complication, and PC and Android apps (I haven’t used them). You create a free account on their server and the list is immediately synced between all your devices. To be clear, I love TF and I have used it for many things for years, most importantly to keep all our family’s medical records on all our devices and to keep them in sync. I just consider TF to be one tool in my toolbox, and for my shopping lists I found I like the AnyList tool.

    JCK
    Participant

    Inspired by this post detailing how to get watched TV shows, I decided to attempt a Movie import script via TheMovieDB’s API. I’m very new to scripting (really only used iOS Shortcuts) and have gotten stuck and could use some direction or assistance.

    The big issue I can’t seem to crack is iterating through the JSON for to pull out the cast and add them to the cast table on the form. I’ve looked through the example of the above of pulling the singular episode details, but the JSON for TheMovieDB is more robust than OMDB and I’ve confused myself.

    Any Ideas?

    var tmdbAPI = 'xxx';
    
    var title_id = 'fld-7f17a3883cf742ca90a732565f687953';
    var released_id = 'fld-4f1d3a5878914910954b65c2f782abfd';
    var imdbid_id = 'fld-0b8bd8338d8f494aa5b7099c42230e70';
    var poster_id = 'fld-bace3b81b9ab4cc9951a9445d12a63b3';
    var summary_id = 'fld-d16b4361266b48ee9c3b88afd29fd5ac';
    var runtime_id = 'fld-f096b51db4c447e18bf10298135dfaa8';
    var tagline_id = 'fld-ac1ad056b5004ed8a19f8d272ae01e2b';
    var cast_id = 'fld-0b85d9aef49f4fd58726f6830a03ba11';
    
    var actor_id = 'fld-07249465a7ea45e8830da27e62b3121d';
    var role_id = 'fld-bf225b3c443248fd97c5737312acd28b';
    
    var itemID; 
    
    function fetchDetailsFromURL() {
        fetchURL = <code>https://api.themoviedb.org/3/movie/${itemID}?api_key=${tmdbAPI}&language=en-US</code>;
        return Utils.getJsonFromUrl(fetchURL);
    }
    
    function fetchCastFromURL() {
        fetchURL = <code>https://api.themoviedb.org/3/movie/${itemID}/credits?api_key=${tmdbAPI}&language=en-US</code>;
        return Utils.getJsonFromUrl(fetchURL);
    }
    
    function getCast() {
    	var cast = fetchCastFromURL()
    	return cast
    	}
    
    function getData() {
    	var film = fetchDetailsFromURL();
    	
    	var imdbID = film.imdb_id;
    	
    	console.log(imdbID)
    	
    	var itemIds = new Set();
    	var currentItemsByImdbID = {};
       var allCurrentItems = form.getRecords();
       for (let currentItems of allCurrentItems) {
        currentItemsByImdbID[currentItems.getFieldValue(imdbid_id)] = currentItems;
        itemIds.add(currentItems.getFieldValue(imdbid_id));
      }
    	
    	let newRecord;
      	if (itemIds.has("http://imdb.com/title/" + imdbID)) {
      	  	Utils.alertWithMessage(film.title + ' already exists.', 'Sorry.');
      	} else {
    		newRecord = form.addNewRecord();
    		newRecord.setFieldValues({
         		 [title_id]: film.title,
         		 [released_id]: film.release_date,
         		 [imdbid_id]: "http://imdb.com/title/" + film.imdb_id,
        		 [summary_id]: film.overview,
        		 [runtime_id]: film.runtime,
        		 [tagline_id]: film.tagline,
          })	
    	}
    	
    	var Poster = "https://www.themoviedb.org/t/p/w1280/" + film.poster_path
    	if (Poster != null) {
       newRecord.addPhotoFromUrlToField(Poster, poster_id);
      	}
       form.saveAllChanges();
    }
    
    var prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Cancel';
    prompter.continueButtonTitle = 'Go';
    prompter.addParameter('TMDB Number', 'itemID');
    
    prompter.show('Enter an TMDB code', getData)
    

    Here are the TMdb API details: https://developers.themoviedb.org/3/movies/get-movie-credits

    #44536
    Sam Moffatt
    Participant

    You can use form.runScriptNamed('Script Name') to run another form script within the form. I have a script manager form that I centralise and then I can do document.getFormNamed('Script Manager').runScriptName('Script Name') to pull that into my various scripts. This allows you to set up form scripts that are libraries of code that you can use or you can set them up to chain them together as well.

    Looking at your getItemFromClipboard method, you might want to run toLowerCase on the numeric[1] inside the switch that way if something messes with capitalisation the script doesn’t break.

    #44534
    robinsiebler
    Participant

    Ok, I actually made a lot of progress! I figured out how to use a Siri Shortcut to send text to the clipboard and get the clipboard in Tap Forms.

    I have a new script called ‘Get Item from Clipboard’ (It does more than that, but I could not figure out how to chain scripts [if that is possible]) that retrieves the clipboard, parses it, creates a new record and then…tries to populate it. However, that step is failing for some reason.

    Any help would be greatly appreciated!

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

    On mobile, the form scripts are under the “Customize Form” > “Scripts” or if you tap “Run a Script” you can also get to your scripts and manage them. Forms scripts differ from script fields in that they’re executed on demand versus script fields that are supposed to automatically update.

    The way I’ve done this sort of natural language processing is via a script field that uses Javascript regular expressions to match field contents and then update other fields. The reason for this is that if you consider your input (e.g. “3 peaches”) you’re going to want to match “peach” and map that back to a known record.

    Siri’s limited in what conversational features it can do and how applications can integrate. The way I’ve worked around this is using Siri Shortcuts to handle the interaction and then call in a form script in Tap Forms. The video uses a barcode scanner use case but you could create a trigger for Siri to ask for the item to add and then use a dictate text to prompt for input.

    #44527
    robinsiebler
    Participant

    I added saveAllChanges(). That worked. I am not sure what you mean by ‘the 3rd tab’ for scripts; I am doing this on my iPad. I didn’t really understand anything else you said (sorry!). I have attached the latest version of my document.

    I can create a Siri shortcut to run the script. Is it possible to have a Siri shortcut where my wife could say ‘Add 3 peaches to Shopping List’ and have it a) create that record and b) run the script to set the item category?

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

    When you do a setFieldValue you need to also do a document.saveAllChanges() to ensure Tap Forms persists the change.

    Field scripts will trigger automatically when ever a field you refer to in the script changes, including when the record is created initially. If you want to run the script on demand, then you want to create a form script via the third tab instead of a field script. Form scripts only execute when you click the run button for it. If you’re after a situation where if you update a field that it refreshes the value of your target form. Depending on what you’re doing, you can also just use the script field to store the value and if you have a link to form field you can skip the search and traverse the link instead.

    I was looking at the document you sent but it seems out of date based on the field ID’s I see here. It does look like you’ve got a form (Categories) that also seems to be a pick list. You can get the pick lists though it doesn’t do the search for you so I’m wondering if that’s why you did it that way? You can also set up the pick list to update based on the form field directly which doesn’t seem to be how it’s configured.

    #44524
    robinsiebler
    Participant

    So, I guess the only way to do this is via a script. So, after much experimentation, I came up with a script that I think should work, but doesn’t.

    If I attach the script to the record, it seems that it fires immediately and fails, because the record is empty.

    If I add it to the scripts section and trigger it manually (which I very much don’t want to have to do), it gets the right value for the category, but fails to change the Category in the record.

    A) What am I doing wrong?
    B) How to I get a script to fire automatically after an item is selected?

    
    function getCategory() {
    
    	var selectedItem = record.getFieldValue('fld-097c3d751c854b1fb4b528238d48b2c4');
    	var records = 	document.getFormNamed('Products').getRecordsForSearchTerm(selectedItem);
    	return records[0].getFieldValue('fld-18643254818f4efbb85cdc66084ccec4');
    }
    
    function setCategory() {
    	var cat = getCategory();
    	console.log(cat);
    	record.setFieldValue('fld-104d11f1b0074b328dafd7688e87298c', cat);
    }
    
    setCategory();
    
    #44512
    Brendan
    Keymaster

    Hello Robin,

    To create a shopping list form:

    1. Create your new form by tapping the Add Form button.
    2. Add the fields you want to track:

    Acquired / Checkmark
    Item Name / Text
    Quantity / Number
    Category / Text
    Aisle / Number
    Description / Note
    Photo / Photo

    3. If the Acquired field is at the very top, you’ll get a Checkmark button on the records list view that you can tap on when you picked up that item.

    You would then add in all your items by creating new records and then entering in the Item Name and Quantity and other information that you have about the items.

    Then when you’re shopping, just display the list of items and tap on the checkmark button when you pick each one up.

    Before you go shopping the next time, you’d probably want to go through the list and uncheck the items that you want to buy again.

    If you group the records by the Checkmark field, you can have all of the unchecked ones at the top and all the checked ones at the bottom of the list of records.

    Hope that helps a bit.

    Thanks!

    Brendan

    #44510

    In reply to: Back up and passwords

    Brendan
    Keymaster

    Hi Hugh,

    You should move the one that’s in iCloud back into the Library folder. You should not open a Tap Forms document that’s sitting on a cloud storage service such as Dropbox or iCloud Drive.

    If you want backups to be in iCloud Drive for safe keeping, that’s fine. Set the Backup Folder on the Preferences window to a Tap Forms Backups folder you can make on iCloud Drive.

    But if you open and work on the document that’s sitting in iCloud Drive, you risk the embedded SQLite file becoming corrupted due to iCloud syncing things behind Tap Forms’ back.

    The reason you are seeing the file appear back in Library, but empty this time is that you probably also have iCloud Sync enabled for that document and Tap Forms is downloading the placeholder document for you from Apple’s CloudKit servers.

    Scripts has nothing to do with this issue.

    Thanks,

    Brendan

    #44506

    In reply to: Back up and passwords

    Brendan

    There are two identical copies of the file, one in Library/Containers/Tap Forms Mac 5/Data/Documents, the other in a sub-folder of iCloud/Documents.
    If I close Tapforms, it automatically backs up the file (into the correct Backup folder in Library – this does not seem a problem at all.)
    When I next load Tapforms it shows both versions in “Recent”. The one in Library opens without the password, the one on iCloud needs the password. (When I make changes, they appear identically in both files.)
    If I open the file directly from either Documents or Library in Finder, I get the same result.
    Later:
    I have now tried moving the file in Library to Bin then reopened Tapforms; the file immediately appeared in Library even before I tried to open it. This Library version is (now) empty, when I open the one from iCloud it requires the password. But both versions appear in Recent and again, password required for the iCloud one, not for the (new, empty) Library one.
    I wish to keep it in iCloud for the off-site back up, how can I prevent it appearing in Library?
    There is a setting in Preferences for Scripts which is set to Documents. I don’t use scripts though there is one that I was playing with in the file – could this be muddling things?
    Hugh

    #44485
    Sam Moffatt
    Participant

    A path forward might be using a script field and Javascript’s template strings as the template and set the Markdown field.

    You can use the script field to get all of the fields you’re interested in. Then you can use the template strings to compose the Markdown content and set it to a Markdown field. As the fields you reference in the script field are changed, the Markdown field will be updated automatically based on the template in the script field.

    Here’s a quick sample from a movie library (maybe the TF sample one?) which has a few extra fields in it. This shows pulling in a number of fields, handling a table field to gather records (actors) and doing some simple composition. It uses template strings to compose the individual lines with the actor in it and the final Markdown string. The last few lines set the field value of the Markdown field I created, tells Tap Forms to save all changes (very important) and returns the raw Markdown so that I can debug in the script editor.

    
    function Md_Generator() {
    	var movie_title = record.getFieldValue('fld-987c9aac738a4f0fa1d18395902b3fb1');
    	var barcode = record.getFieldValue('fld-7e3ead95de51427fa5a467b2476d58cd');
    	var summary = record.getFieldValue('fld-28cc8f7f082c43818f1169c96c96e5a9');
    
    	var photo_count = record.getFieldValue('fld-55340bfd611b411b87da481ae23e8db9');
    	var actors_total_cost = record.getFieldValue('fld-1837d1a6be83424a90e0e7ebdd6265e3');
    	var imdb_website = record.getFieldValue('fld-9bc90613e8db45fea77579f35eb53b9d');
    
    	var actorLines = [];
    	var actors = record.getFieldValue('fld-984cf79ccafb45a381b0f95b0aa28e78');
    	for(var actor of actors) {		
    		var first_name = actor.getFieldValue('fld-92b3b496a6cb4c20a32d36aa61e7a04f');
    		var last_name = actor.getFieldValue('fld-a907066570844290a27940d34de98b4f');
    		var fee = actor.getFieldValue('fld-b1ea1f22da5f421c93e1e20520e3ea22');
    		
    		actorLines.push(`- ${first_name} ${last_name} (Fee: $${fee})`);
    	}
    	
    	var actorString = "No actors listed."
    	if (actorLines.length > 0) {
    		actorString = actorLines.join("\n");
    	}
    
    	var markdown = `
    # ${movie_title}
    
    Barcode: ${barcode}  
    Photos: ${photo_count}  
    Actor Cost: ${actors_total_cost}
    
    ## Actors 
    ${actorString}
    
    ## Summary
    ${summary}
    
    ## Links
    - [IMDB Link](${imdb_website})
    `;
    
    	record.setFieldValue('fld-d0a67ce5cf1a4ab8b0a3e2357cc18d45', markdown);
    	document.saveAllChanges();
    	return markdown;
    }
    
    Md_Generator();
    
    #44469
    Brendan
    Keymaster

    Hi Juan,

    There’s no built-in function for doing substitutions like that outside of a static text object on the Mac version using a custom layout.

    With a static text object on a custom layout, you can do things like this:

    Dear [First Name],

    Your account is now overdue by $[Amount Due]

    Sincerely,

    The Management

    But it’s not using the Markdown editor. It’s just using the regular rich text editor.

    And you will see the substitution results only at print time.

    If you were to use a script running against the Markdown field, you’d just end up replacing the values. Although I suppose if you set the Default Value on your Markdown field to your template, whenever you added a new record, you’d get the untouched template value which you could then run a script on to do the substitutions.

    Thanks,

    Brendan

Viewing 15 results - 1,261 through 1,275 (of 2,952 total)