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,176 through 2,190 (of 3,130 total)
  • Author
    Search Results
  • #39727
    PICOT Jean-Bernard
    Participant

    Yes indeed. I confirm after having discovered it by surprise today, just before your comment.

    For the followers of this item, to explain again, it is NOT the form button to press (which gives access to fields and scripts and arrangement of the default form), BUT to the very little button (showing drawing of tools) on the upright of the table view (very small indeed) and give you access to possibly hide (or not) table columns and arrange their order from left to right.

    Thanks for commenting.

    #39720
    Sam Moffatt
    Participant

    On the Link to Form field there should be a little tick icon that will let you search for existing records already in the form on the other side. On the Mac it should be under the record list and on iOS it’ll be in the top right corner when you tap into the Link to Form field. It should be there on the Link from Form field assuming it is set up as Many to Many, you might need to toggle the “Show Inverse Field” option on the Link to Form field to recreate the Link from Form field if it was created as a one to many field. A Many To Many or JOIN type should be a table on both sides (e.g. the Link to Form and Link from Form). A One to Many Link From Form will render as a single record view and if you created the inverse field before changing the type to Many to Many then it will retain that (I recall that might have been a bug that was fixed but perhaps not).

    If in your user form you store a per site password then you might need a third form to store the unique passwords per site (user link from form, site link from form and password). I have some other posts on the forum about modelling such a relationship.

    Internally Tap Forms store a record ID for each record and it’s backed by a document store called CouchbaseLite (which is where the CouchDB and Cloudant sync comes from). This is a semistructured data store and in a sense could be modelled as a key/value data store where the key is the document identifier and the value is a JSON document. The key exists however it’s abstracted away from the user most of the time.

    CouchDB/Couchbase/CouchbaseLite doesn’t have queries in the SQL sense but instead you write a map/reduce function in Javascript. The Saved Search feature in Tap Forms is an abstraction of that interface to build the query for you. Tap Forms doesn’t expose a way of building your own map/reduce functions to power a saved search but you can do this with your own CouchDB instance.

    Depending on what you’re trying to achieve, you can replicate all of your data into a CouchDB instance and get access to it there. I personally do this and have built tooling to do a bunch of different tasks. Having your own CouchDB enables full access to your data and if you follow the way Tap Forms works you can also use this interface to push data into Tap Forms.

    Attachments:
    You must be logged in to view attached files.
    #39694
    Chris Ju
    Participant

    Hello,

    does anyone have the programming code in java script for reading the Hardware-UUID?

    Terminal command from stackflow:

    ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'

    I want Tap Forms to read the Hardware-UUID and write it to a field on every change of an entry. The next step could be to add a log entry (in a log form) for changes … on every change a new entry in the log form will be generated (one time calculation)…

    Thanks a lot
    Chris

    #39690
    Brendan
    Keymaster

    @Max, I can answer your UPC data from Internet question by pointing you to the code snippet on the Scripts manual page under the topic “Fetch Movie Data from Web Service”.

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    There’s sample code there that shows how to fetch data from the Internet given a barcode.

    #39688
    Max Heart
    Participant

    Thanks a million, Sam. I will download the files and will give you feedback asap.

    EDIT: It works. Amazing. I will now try to transfer your script and adapt it to my forms which are relatively similar.

    Just a curious side question, slightly OT: You have UPC as one field. Would it be possible to pull item data from the internet automatically by using the UPC?

    #39680
    Sam Moffatt
    Participant

    Ok! I did some work to set up a sample document with the scripts in it. There were some modifications to the original ones I posted, this edition doesn’t prompt to confirm the item name, it has support for automatically creating new records and it prompts if you try to reassign an item from one box to another if you want to do it.

    I’ve attached three files:

    • Boxes-20200228.tfarc: a Tap Forms archive containing all of the forms with some sample data.
    • Boxes-20200228.tff: a Tap Forms Form Template with the box forms.
    • Script Manager-20200228.tff: a Tap Forms Form Template with the Script Manager including an updated set of form scripts.

    Took a bit of time to put this all together and test that it works roughly the way I’d expect. It includes two Link to Form fields, one set up as a 1:M type and another set up with a JOIN type. The “Bulk Add to Form” script will handle updating the 1:M field properly and the text field referred to by the JOIN type.

    Right now it’s a little chatty, you might want to tune that down a little or bypass some of the confirmation items.

    Let me know if that helps a little more with figuring things out. If it makes sense, I might put it up on the template exchange as well.

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

    Hi Guillaume,

    Those two shortcut actions were accidentally left in there. I’ve removed them for the next update. I tried to make them work, but because of the dynamic nature of Tap Forms, I couldn’t get it to ask you for values for the fields, so I couldn’t make that work. At least not until Apple enhances Shortcuts to allow dynamically assignable parameters. So right now the only shortcut that works is the one for running form scripts.

    But it might be interesting to integrate Tap Forms directly with HealthKit so you could import all your HealthKit data into Tap Forms. I workout every day myself and use the Activity app to view my health data. So it would benefit a lot of people I think. I’ll think about it.

    Thanks,

    Brendan

    #39658
    Sam Moffatt
    Participant

    I wrote a script a while back to combine multiple values from Link to Form field for precisely the reason of being able to search for those records. You can just have the script field contain the data and it’ll show up in search, it’s exactly how I use it. I use them on Table fields in some places as well to help roll up aggregates.

    #39656
    Edu Neve
    Participant

    Hello,
    I have zero experience with Javascript and I’m struggling to understand the provided documentation regarding scripts. The reason I’m considering scripts is because I really want to be able to search and sort fields that link to other forms, but from what I’ve read in the forums this is unfortunately not possible yet (this is absolutely my number one request for future development).

    So, I figured an alternative would be to create a script that copies the contents of a field that links to another form, into a regular field. This way, when I sort or create saved searches/filters, I can point to the regular field that would have copied the relevant contents.

    So, all I want is a simple automated copy-paste of the text or numeric contents of a field (that links to other forms) into another field of my form. I haven’t been able to find a step by step guide in the documentation or in the forums.

    I see that I’d use “get field value” and “set field value” or “set multiple field values”, but I don’t know how to go about it. Do I create the script as a field, or do I simply add it to the Scripts pane? And once I create the script, what would I type there?

    Any help would be much appreciated. Thank you.

    #39655
    Max Heart
    Participant

    OMG, Sam, I feel so bad and like a complete idiot … I appreciate your help so much but I am not able to translate it to my database.

    If you still have patience to advise I would highly appreciate it. I will try to describe precisely where I am:

    – I have two forms: “Inventar-Boxen” which has all the boxes and “Inventar-Inhalte” which has all the individual items. The field “Inhalte” in Inventar-Boxen is linked as one to many to the form Inventar-Inhalte. “Show reverse link” is enabled
    – The form “Inventar-Boxen” has the following fields: “Boxname” (Calc Field: Box number, box name, box type), Place, box number, box type, contents (“Inhalte”: the linked field), Barcode (the QR code field – a calc field “Box+box number”)
    – The form “Inventar-Inhalte” has “Foto”, “Item” (Calc Field: Manufacturer + item name), Boxen (re-link from the “Inventar-Boxen” form), “Barcode-ID” (this is the bar code identifier), “category”, “label”, “notes”, “invoice”, “purchase date”, …

    What I did:
    – I created the script manager form and copy pasted your “Prompter functions”
    – I copy pasted your second script into the script section of “Inventar-Boxen” and named it “Bulk Add”. I assigned Alt+Cmd+Y as a keyboard short cut.
    – I tried to exchange your fields with mine. However, I am already lost with the field IDs

    Is there a chance to have a look at your tap forms file with just one set of sample data? Maybe I would be able to understand the scripting concept better then.

    Again thank you very much and best regards, Max
    –

    #39652
    Sam Moffatt
    Participant

    So for the second script, I have two forms, one is “Boxes” which stores the details about the physical box and then I have another form for “Purchases”. “Purchases” was the name of my original Bento library from what feels like a decade ago now and was mostly flat and denormalised. As I’ve gone along I’ve started to normalise everything but it’s all over the place. I had added ages ago “Bag Barcode” and “Storage Box” to the “Purchases” form but didn’t really do much with them. When I started moving, I decided I wanted to have a first class ‘Boxes’ form.

    The ‘Boxes’ form looks like this:

    Boxes: (frm-8ba92c77b5e8476a987945f40ff2b41a)
            'Title' text (fld-e289240daccc40409d75aee26493110c)
            'Box ID' text (fld-f25492cf56384369b278f7ea41ee258f)
            'Note' note (fld-69754dee7e9247e0b3087e2526881626)
            'Dimensions' text (fld-3e5e30f1d352495f989cc0dc1b306128)
            'Box Type' text (fld-97b2ab2bdbb1400d9384c7634e7c6d48)
            'Box Photos' photo (fld-72a520cff50a4bbd92f1e8ff6eec91db)
            'Purchases' form (fld-482c4f5c71ba4cd7a06c32d1c1d7d983) join 'Purchases' (frm-efc0199a2b1543f79e722383014533b0)
                             ON Boxes.Box ID == Purchases.Storage Box
            'Containing Box' text (fld-fe868108cdd844d895ea982e820b346c)
            'Boxes' form (fld-74466a4b96dc43b4bcbe153646b76911) join 'Boxes' (frm-8ba92c77b5e8476a987945f40ff2b41a)
                             ON Boxes.Box ID == Boxes.Containing Box
            'Tracking Number' text (fld-54af5c1e20e14d20a7c82a40679a2a8a)
    

    It has some metadata about the box such as a title, it’s Box ID (which maps to the box_id_id variable) which is the unique identifier tied to the barcode, it has some other details that are useful and then it has a link to my existing ‘Purchases’ form. There is a ‘Link to Form’ as “JOIN” field here to tie the box record to the purchases record. I also have an extra field for when this box is inside of another box plus a ‘Link to Form’ self-JOIN field. Since some of these boxes are being shipped, they are also tied to a tracking number (I should probably have made this a link to the shipments form I have in this document but didn’t).

    My Purchases form looks a little bit like this, I’m going to cut out some fields because it has 121 individual fields in it that aren’t particularly relevant. Here are the first few.

    Purchases: (frm-efc0199a2b1543f79e722383014533b0)
            'Image 01' photo (fld-e631165b67374734a3b8f384708b5922)
            'Title' text (fld-0d0edd2552ea461e929f806a4e5552b5)
            'Subtitle' calc (fld-45ef928f87e24bcd93e6751c8c21a6cb)
                    Referenced Fields: 
                     - State (fld-9402f8c0d53c43b986fee4ebc3468929)
                     - Colour (fld-a8626656cc90455ea9336dd2488d4aef)
                     - Category (fld-6fdd09891a8c4d73be1b24aa07d077be)
    
            === 'State Details' section (fld-21cdfa78aaf44d3b83e5c0e16c8d40d1) ===
            'State' text (fld-9402f8c0d53c43b986fee4ebc3468929)
            'Previous State' text (fld-636a7a4671c14877b1b17ea1b579cef5)
            'State Watcher' script (fld-45463af0b409465ea78ad7c498ee896d)
            'Colour' text (fld-a8626656cc90455ea9336dd2488d4aef)
            'Category' text (fld-6fdd09891a8c4d73be1b24aa07d077be)
    
            === 'Main' section (fld-76597ce17f924c25bbcb195df984331c) ===
            'Date Created' date_created (fld-0d049abe706b41afb680ab9a1bf99d46)
            'Date Modified' date_modified (fld-59a06347614e48e8bf547a855b781582)
            'Purchase Date' date (fld-ccbd9a8f51d34246bebfb31aa4e397dd)
            'Ship Date' date (fld-cb3a9886ac7f4ec487447801a3911a1a)
            'Received Date' date (fld-bb17d48e41c7423692ab586f6c884d05)
            'Order ID' text (fld-e3e66a0f2e5c4df7b9496f65355e0bcf)
            'Marketplace' text (fld-c163aba17ae64c4d93b5a53819a139dc)
            'Store Name' text (fld-3d98dc6cdcae4a88909c97c80dde7bfb)
            'Brand' text (fld-1e250019d7b249f282cc572814d3e71d)
            'Source' web_site (fld-da9d866bf3ca4d47aade04a77efd7301)
            'Source Scraped?' check_mark (fld-a0557d4c58334bbc81b356b99f6f0a1d)
            'Source Scraper Script' script (fld-429e3e7ca20a49d38b26417e25e6db26)
            'Item Key' text (fld-ae7379d699e9473aa2ab16a2a2f002d4)
            'Price' number (fld-08129d71ab0f4fa4a2749456281fca07)
            'Shipping Tracking Number' text (fld-6ea45a9c141343628940bfbcfa38ee90)
            'Shipping Carrier' text (fld-12644a7a4ae24ed8a7926123832d3557)
    
            === 'Storage' section (fld-f99f779335f54b9cb0a4179a90bb97dd) ===
            'Bag Barcode' text (fld-32d459f0b5fb4dc4974795c484832af1)
            'Storage Box' text (fld-c08e3a9eb7784d7f8ee3a5576c0adffa)
    

    Reasonably generic listing of fields for an object you’d buy, again it’s a little flat because of how I modelled it in Bento but you can see at the end in the storage section the two fields: ‘Bag Barcode’ (which maps to the bag_barcode_id field) and ‘Storage Box’ (which maps to the storage_box_id field). These are simple text fields that have the unique barcode for the bag storing the item as ‘Bag Barcode’ and then ‘Storage Box’ is the barcode of the box that this item is currently contained in.

    #39650
    Max Heart
    Participant

    Hi Sam,

    thank you so much for your two long posts with explanations. I will try to understand them and modify the variables so that they fit to my forms.

    So far
    – I imported your Script Manager form
    – I added the Prompter script to the Script Manager form
    – I created a script field in my box form and pasted your full script from the second post
    (… and I bought a barcode scanner for my Mac)

    Now I have to understand and adapt the script. The field which contains my QR code of the box is called “Barcode”. Is this field called “box_id_id” in your script?

    #39649
    jolinwarren
    Participant

    TJ, I just read your blog post on Bobby (an app which I installed a few years ago and then never used), and after reading about its limitations, thought, “I should set up a Tap Forms database to track my subscriptions instead”. Your blog post helped clarify in my mind what I would want to track for subscriptions, and why (which match yours). I’ve been using Tap Forms for many years, so it’s the place I would naturally want to do this. I headed over to the forums here to look into a couple of things and came across your post, a nice little circle!

    However, you would probably need a couple of fields to store the subscription costs based on whether they’re annual fees or monthly fees. Because Tap Forms wouldn’t be able to detect if you typed in “$2/month” or “$24/year”.

    I was thinking of handling this a different way, basically having a ‘price’ currency field and then a tickbox for “annual” (default being monthly for me, but you could reverse that). Or there could be a choice field if weekly, biannual, or other frequencies need to be supported. Then I would have two calculation fields, “monthly cost” and “annual cost”, and using the price and tickbox fields, it would be possible to calculate and display both.

    I haven’t built anything yet, but I’m happy to share it when I do if you’re still interested.

    Cheers,
    Jolin

    #39648

    In reply to: Finding earliest date

    Larry Stoter
    Participant

    I actually want to find the earliest date in a field as a step in a more complex script.

    However, I have an apparently easy solution :-) Create a new calculation field Date#, simply put the Date field into the calculation and then set the Result Type to Number. The Date# field then shows numbers – not sure what numbers but the earliest date has the smallest number in the Date# field.

    Which seems to do what I want.

    #39645
    Sam Moffatt
    Participant

    Ok, so I found the other one which is actually a variation of the one I posted though simplified in a way. It works on two forms: one for boxes and a second for purchases that has a “box ID” field in it as a text field.

    This uses the prompter functions again and also getRecordFromFormWithKey to find matching records.

    Let’s get started!

    var PARENT_SCRIPT = 'Boxes::Bulk Add To Box';
    document.getFormNamed('Script Manager').runScriptNamed('Prompter Functions');
    document.getFormNamed('Script Manager').runScriptNamed('getRecordFromFormWithKey');
    

    Define the PARENT_SCRIPT to prevent stuff like Profiler running it’s self tests. My internal version of getRecordFromFormWithKey currently has profiler support, I’ll update it later. We need the prompter functions again from earlier as mentioned.

    // Boxes
    var box_id_id = 'fld-f25492cf56384369b278f7ea41ee258f';
    
    var box_id = record.getFieldValue(box_id_id);
    

    This form I have this in is called “Boxes” and it has a field called “Box ID” which we grab when we start the form script. These are those variables.

    // Purchases
    var state_id = 'fld-9402f8c0d53c43b986fee4ebc3468929';
    var bag_barcode_id = 'fld-32d459f0b5fb4dc4974795c484832af1';
    var storage_box_id = 'fld-c08e3a9eb7784d7f8ee3a5576c0adffa';
    var title_id = 'fld-0d0edd2552ea461e929f806a4e5552b5';
    

    Purchases is the track of things I bought, it has it’s own barcode (in “Bag Barcode”) and it also has a text field for the storage box. There are also state and title fields for it as well.

    async function start(){
    	try {
    		while (1)
    		{
    			let barcode = '';
    			let scanBarcode = await promptText("Scan Bag", "Barcode:");
    			
    			if (!scanBarcode)
    			{
    				break;
    			}
    			
    			console.log(scanBarcode);
    

    If this looks familiar, it should because it’s the previous code without the zipcode and carrier removed. Also “Shipment” is now “Bag”. Cool beans!

    let correctBarcode = await promptConfirm(`Is ${scanBarcode} correct?`);
    			
    			if (!correctBarcode)
    			{
    				console.log('Incorrect barcode, skipping');
    				continue;
    			}			
    

    This part is new, it asks if the scanned bar code is correct. This lets you hit cancel if it’s wrong. If you’re using this with a hand held scanner (which I am), then generally it’ll insert an “enter” at the end of the input. This means you can scan a barcode, validate it on screen and scan the barcode again to confirm this dialog. It gives you an escape key to abort from.

    
    			let targetRecord = getRecordFromFormWithKey('Purchases', bag_barcode_id, scanBarcode, false, false);
    				
    			if (targetRecord)
    			{
    

    This looks for a record in my Purchases form looking in the bag_barcode_id field for the value of scanBarcode that we just scanned. The last two prevent some optimisations and also prevents autocreating records.

    
    				let title = targetRecord.getFieldValue(title_id);
    				
    				let correctTitle = await promptConfirm(`Is ${title} expected?`);
    				
    				if (!correctTitle)
    				{
    					console.log('Incorrect title, skipping');
    					continue;
    				}
    

    We do an extra confirmation to check that the title matches what we expect. Again if you are using a barcode scanner you can scan again to progress.

    
    				// Set the delivered flag just in case it isn't set already.
    				targetRecord.setFieldValue(state_id, 'Delivered');
    

    My purchases has a state field and we just update this to delivered when we’re scanning something. My state tracking was a later addition so this helps to clean up anything I touch.

    
    				let boxId = targetRecord.getFieldValue(storage_box_id);
    				
    				if (!boxId)
    				{
    				targetRecord.setFieldValue(storage_box_id, box_id);
    				}
    				else
    				{
    					Utils.alertWithMessage('Box ID Already Set', `This barcode already has already been scanned with ${boxId}`);
    				}
    

    We then check to see if we have a box ID already and if it isn’t set we set it. If it is set then we flag this with the user. In your case you could change this up to confirm with another prompt (like shown earlier) and confirm reassigning the boxes.

    
    				document.saveAllChanges();
    				console.log("Updated existing record for " + scanBarcode);
    			}
    

    Save all the changes and I make a log message. I like log messages.

    
    			else
    			{
    				Utils.alertWithMessage('Unable to find record', `No matching record for ${scanBarcode}`);
    			}
    		}
    

    The else is to prompt a message saying we can’t find the barcode.

    
    	} catch (error) {
    		console.log("Error: " + error);
    	}
    }
    

    Just like the last one, we catch the error and log it as a fall back.

    
    if (box_id)
    {
    	start();
    }
    else
    {
    	Utils.alertWithMessage('Invalid box', `Invalid box ID found: ${box_id}`);
    }

    This is a little different, it checks to see if you have a record in the Box form before starting up. The intent is that you are in a box and scanning items into said box.

    Here’s the script in full:

    var PARENT_SCRIPT = 'Boxes::Bulk Add To Box';
    document.getFormNamed('Script Manager').runScriptNamed('Prompter Functions');
    document.getFormNamed('Script Manager').runScriptNamed('getRecordFromFormWithKey');
    
    // Boxes
    var box_id_id = 'fld-f25492cf56384369b278f7ea41ee258f';
    
    var box_id = record.getFieldValue(box_id_id);
    
    // Purchases
    var state_id = 'fld-9402f8c0d53c43b986fee4ebc3468929';
    var bag_barcode_id = 'fld-32d459f0b5fb4dc4974795c484832af1';
    var storage_box_id = 'fld-c08e3a9eb7784d7f8ee3a5576c0adffa';
    var title_id = 'fld-0d0edd2552ea461e929f806a4e5552b5';
    
    async function start(){
    	try {
    		while (1)
    		{
    			let zipcode = undefined;
    			let carrier = '';
    			let barcode = '';
    			let scanBarcode = await promptText("Scan Bag", "Barcode:");
    			
    			if (!scanBarcode)
    			{
    				break;
    			}
    			
    			console.log(scanBarcode);
    			
    			let correctBarcode = await promptConfirm(`Is ${scanBarcode} correct?`);
    			
    			if (!correctBarcode)
    			{
    				console.log('Incorrect barcode, skipping');
    				continue;
    			}			
    			
    			let targetRecord = getRecordFromFormWithKey('Purchases', bag_barcode_id, scanBarcode, false, false);
    				
    			if (targetRecord)
    			{
    				let title = targetRecord.getFieldValue(title_id);
    				
    				let correctTitle = await promptConfirm(`Is ${title} expected?`);
    				
    				if (!correctTitle)
    				{
    					console.log('Incorrect title, skipping');
    					continue;
    				}
    			
    				// Set the delivered flag just in case it isn't set already.
    				targetRecord.setFieldValue(state_id, 'Delivered');
    				
    				let boxId = targetRecord.getFieldValue(storage_box_id);
    				
    				if (!boxId)
    				{
    				targetRecord.setFieldValue(storage_box_id, box_id);
    				}
    				else
    				{
    					Utils.alertWithMessage('Box ID Already Set', `This barcode already has already been scanned with ${boxId}`);
    				}
    				document.saveAllChanges();
    				console.log("Updated existing record for " + scanBarcode);
    			}
    			else
    			{
    				Utils.alertWithMessage('Unable to find record', `No matching record for ${scanBarcode}`);
    			}
    		}
    	} catch (error) {
    		console.log("Error: " + error);
    	}
    }
    
    if (box_id)
    {
    	start();
    }
    else
    {
    	Utils.alertWithMessage('Invalid box', `Invalid box ID found: ${box_id}`);
    }
Viewing 15 results - 2,176 through 2,190 (of 3,130 total)