Generic script to allow adding a record from Shortcuts

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Generic script to allow adding a record from Shortcuts

Viewing 1 reply thread
  • Author
    Posts
  • December 16, 2020 at 3:18 AM #42869

    Martin Kendall
    Participant

    Hi,

    I just made a quick utility to simplify adding records to Tap Forms from other apps.

    It actually allows adding of records from any app (e.g. Shortcuts, Drafts) that can call a URL.

    To use:
    1) Install: Add the attached script as a form script to the form you want to be able to add records to.
    2) Run the script in Tap Forms and it will display the URL you need to use in Shortcuts to add a record
    3) Create a Shortcut calling that URL with the parameters matching the field names in the form (for the fields you want to set)

    I’ve only added support for adding text values, URLs and photos, but there is nothing to stop other field types, such as rating, being added.

    Hope someone finds this useful,

    Martin

    Attachments:
    You must be logged in to view attached files.
    December 16, 2020 at 11:02 PM #42878

    Sam Moffatt
    Participant

    Nice start to a generic entry point! I have some suggestions for improvements :)

    Instead of this long line:

    if (param == 'JLRouteScheme' || param == 'JLRouteURL' || param == 'formID' || param == 'JLRoutePattern' || param == 'docID' || param == 'scriptName')
    

    You could use an array and simplify the if statement and skip to your else directly by using Array.includes:

    var ignoredParams = ['JLRouteScheme', 'JLRouteURL', 'formID', 'JLRoutePattern', 'docID', 'scriptName'];
    if (!ignoredParams.includes(param)) {
    

    The other thing would be to use a switch statement instead of the if/else:

    			var theField = form.getFieldNamed(param);
    			if (theField == undefined) {
    				console.log(`No field called ${param}`);
    				continue;
    			}
    			switch(theField.fieldType) {
    				case 'text':
    				case 'web_site':
    					record.setFieldValue(theField.getId(), parameters[param]);
    					break;
    				case 'photo':
    					record.addPhotoFromUrlToField(parameters[param], theField.getId());
    					break;
    				case 'script':
    					console.log('Cannot set value for a "script" field type');
    					break;
    				default:
    					console.log(`Unsupported field type ${theField.fieldType}`);
    			}
    
Viewing 1 reply thread

You must be logged in to reply to this topic.