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,111 through 1,125 (of 2,951 total)
  • Author
    Search Results
  • #45707

    In reply to: Aggregate Amount Field

    Brendan
    Keymaster

    Hi Tim,

    Yes you can do this with a Field Script.

    Use this code in a field to display the aggregate total of all the records in the form for the specified field:

    function getFieldTotal() {
       var field_id = 'fld.....'; // whatever the field ID is for the field you want the total of.
       var total = form.getTotalOfField(field_id);
    
       return total;
    }
    
    getFieldTotal();
    #45678
    Sam Moffatt
    Participant

    The other day I had a random thought: could I port the old Drug Wars game that I used to play on my calculator over to Tap Forms 5? Since you’re reading this you probably guessed the answer is yes!

    For those not aware, Drug Wars was a popular game for the TI-82/TI-83/TI-84 series of graphical calculators that one might find in a high school maths class. I found a version of it online in a Gist and set to porting it over to Tap Forms.

    I used some of my prompter support functions (also available via Script Manager), added some helper functions to emulate what the calculator provides and mostly faithfully ported it into Javascript and Tap Forms 5 for Mac.

    Note: this won’t work on iOS because Utils.alertWithMessage on iOS doesn’t block like it does on the Mac. Hopefully Brendan can figure out how to make that consistent, or suggest a change to make it work, so that you can use Tap Forms for iOS and iPadOS to also play the game.

    If you’re interested in checking it out, it’s here in a Gist on GitHub: https://gist.github.com/pasamio/3238964489c6594ab1983b7aaa02b91b

    As a note, it’s a Javascript almost lines for line replication of what the original TI-BASIC programming. It’s hampered a little because TI-BASIC has labels/goto whilst Javascript doesn’t provide that feature (probably because goto considered harmful) so that leads to more creative solutions to flow control. There’s an elegance in how the spaghetti code in TI-BASIC works that perhaps reminds us how things used to be.

    And now to ping the keymaster because I’m sure this post will get flagged…

    • This topic was modified 3 years, 12 months ago by Sam Moffatt.
    • This topic was modified 3 years, 12 months ago by Sam Moffatt.
    #45648
    Miguel Centeno
    Participant

    I was looking to the above script you posted (#post-39818) but I have no idea where str = str.replaceAll(‘Blue’, ‘Red’); is supposed to be placed.

    My goal is to have a Run Script button to change part of a URL, from time to time.

    I’m doing some genealogical research using a particular Chrome extension viewer, which is more user friendly than the original viewer of the archive site. The downside is the extension changes the original URL. So, in the end of the day, after pasting a lot of URLs to TF, I wish to replace a part of those URLs, so I can have the original ones. Basically, to find “viewer” and replace it with “ViewerForm.aspx”:

    https://digitarq.arquivos.pt/viewer?id=4805309&FileID=PT-ADLSB-PRQ-PFAR02-004-M4_m0027.jpg
    https://digitarq.arquivos.pt/ViewerForm.aspx?id=4805309&FileID=PT-ADLSB-PRQ-PFAR02-004-M4_m0027.jpg

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

    Can you post what script you have so far? Then I can see what you need to do to accomplish what you want.

    #45639
    Miguel Centeno
    Participant

    Hi Brendan, I’m afraid my programming skills are too basic, can you please help me with the complete script for that?

    #45634
    Brendan
    Keymaster

    You’d just need to use the JavaScript replaceAll() function for that.

    str = str.replaceAll('Blue', 'Red');

    #45633
    Miguel Centeno
    Participant

    Very useful script but how can I find and replace a specific word in a paragraph?

    #45604
    Sam Moffatt
    Participant

    I’ve been wondering about this on and off for a while, HTML and CSS still are pretty mediocre at multipage printing when using complex elements like tables. I’ve also wondered about alternative solutions and embedding but particularly for iOS some of that could end up heavier than the app itself (LaTeX being my own tool of choice paired with pandoc to support HTML or Markdown). I think a web browser based layout could work on iOS as a display layout system at least and perhaps the JSC work could easily be applied to a WKWebView. In theory you could use TF’s Nearby Sync with the existing web view that is loaded from the web site field to embed stuff but I haven’t been bored enough to figure out how to make it work.

    In doing another search for stuff again, I came across Carbone which has an API that accepts documents, templates them and will hand back a PDF. It has a 100 doc free tier for their API renderer which might work as well as an open source version without a REST API. I’m wondering if the API version might work with TF via a script and time permitting this weekend I might give it a spin.

    #45552
    Brendan
    Keymaster

    Hi,

    Yes, you would want to setup a search for each of the forms. But Tap Forms doesn’t have a Saved Search operator which would directly let you search for every November 3rd. You could pick one November 3rd from a specific year.

    Although if you created a Calculation or Script field which returned just the date without the year included, then you could search for all November 3rds (or whatever date). It’s just the normal date search would need to know the year. Although there are some built-in dynamic date operators such as “this week”, “next week”, “last year”, “next month”, etc.

    You would need a search for each form though as the global search mechanism that can search across forms just does a textual search and not for specific fields.

    #45534
    Bernard Tan
    Participant

    Hi, is there anyway or script to set the Record List font size and Color?

    What im trying to achieve is…

    Example : On my list of records, im display 4 field lines for each record (yes, this can be selected on the Single Column List View field options).. But for each record, i would like the first 2 lines(in the record list) to be displaying in bigger font size, and with a different font colour. Is this achievable by scripting, or any method in TF?

    note: i only want the colour of the text to change, not the entire record background color. Also i understand the field value color can be changed, but i only sees the changes on my display layout, and not on the recordlist

    Any suggestion and help would be greatly appreciated, and thank you in advance

    #45481
    Kirk Williams
    Participant

    @Daniel Leu
    @Sam Moffatt

    Wow – I simply can not thank you both enough for taking the time to assist me!

    Daniel, your second “simplified” suggestion seems like it may be the perfect solution (and one that I NEVER would have thought of on my own anytime soon)! I’ve just tinkered a bit with some “dummy” test product forms and it works flawlessly. I now just need to play some more in order to work out different scenarios such as incorporating records with existing Asset IDs, error corrections, etc. Note that this ‘playing’ is for my own self-education, not for verification of the script lol. If this strategy functions as it appears it will, it will prove to be the answer I’ve been agonizing over for months!

    Sam, our barcoded labels are provided by the hospital I work at. While I am not certain of the exact format, I presume the code is for the six-digit numeric value only (based on the fact that “PSC” is an acronym for our department likely added internally for clarification). I can’t imagine the text prefix would make sense, or even be recognized by the other applications that incorporate scanning. I am also 100% on board with your suggested potential of using field ids for further relative functions! I’ve only used tapforms for basic, personal projects thus far and it’s becoming obvious that I’ve underestimated its capabilities.

    Regarding the migration of data: I actually do have all the source data imported already (and I’m admittedly OCD with backing up, so no worries there!) and modified to reflect the references properly. By that I mean I’ve updated fields with textual data in place of the corresponding SQL table/field IDs they originally imported with. My point in mentioning that is I now realize I could have saved myself a lot of time and effort by scripting those replacements. Lesson learned.

    FWIW, I am treating this document as a sandboxed environment for the time being, as the GLPI application is still operable. With that in mind, I have the confidence to tinker without the risk of compromising any critical data. Ultimately, our department is abandoning the use of the GLPI database, but I personally use it frequently and think it’s well worth the time to migrate, even if only for my own use (which is likely since our health system is almost entirely windows-based).

    I’m certain I may have some additional questions as I dig deeper, but I am beyond grateful to you both for your time and help!!!!

    K

    #45473
    Sam Moffatt
    Participant

    Oh and on the migration front, I’d 1:1 import everything to start with. Get all of the data in and verify it landed safely. You know that data model works, for certain definitions of work, so start there. Data migration can be complicated enough without changing things along the way. Get it all over in one piece and then progressively make changes. Always keep a backup and if possible, keep multiple copies using something like Time Machine. The last thing you want is to be second guessing if your data migration lost data.

    For normalising your data, what I’d suggest is leveraging table fields. Table fields allow you to embed sub data into your forms. If you’re just tracking textual data, a table field in a sort of key/value setup will let you track arbitrary data easily. You can use scripting to prefill keys in the table based on an entity type to get stuff over. This gives you prompts for values that can be completed whilst being relatively flexible.

    This does limit the utility of Tap Forms in that these values aren’t as accessible but short of multiple layouts per device type (also only available on the desktop), I don’t think there is an out of the box solution for what you want (visible fields based on the value of another field). You might be able to use sections to make it harder to hide those fields in a really wide form but that’s still a hard data normalisation problem.

    #45471
    Daniel Leu
    Participant

    After some more thinking and tinkering, I got a simpler version….. You have a form Asset ID with a number field number with auto increment and start value set to 2048. Then you have several product forms. Each has two text fields, one called Name and the other Asset ID. Additionally you have a field script shown below.

    This script is called when a new record is created. It adds a new record in the Asset IDs form which creates a new unique number. Then this number is stored in the proper format in the Asset ID field. That’s a bit easier to use than my first response.

    function Get_Asset_Id() {
    	// id of Name field. This is only needed to force execution of this script
    	// when a new record is created.
    	const name_id = 'fld-xxx';
    	let name = record.getFieldValue(name_id);
    
    	// id of Asset ID field
    	const asset_id_id = 'fld-xxx'
    
    	// id of number field in Asset IDs form
    	const number_id = 'fld-xxx'
    
    	// Check if Asset ID field is already set
    	if (record.getFieldValue(asset_id_id)){
    		console.log("Asset ID already set. Aborting")
    		return
    	}
    	
    	// Create new Asset ID number
    	let asset = document.getFormNamed("Asset IDs").addNewRecord();
    	
    	// get asset number
    	let assetNumber = asset.getFieldValue(number_id)
    	console.log("got new asset number: " + assetNumber);
    	
    	// store value
    	record.setFieldValue(asset_id_id, "PSC" + String(assetNumber).padStart(6, '0'))
    	document.saveAllChanges();	
    }
    
    Get_Asset_Id();

    In order to use this script, you have to set the three field ids and the “Asset IDs” form name has to match or you adjust the script accordingly.

    Hope this helps!

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #45468
    Daniel Leu
    Participant

    I would create a dedicated form to keep track of your asset ids. This form has a number field that is auto incremented with an initial value of 2014 (next ID). This way, all Ids are unique. A second field of type calculation with return type text is used to create your unique asset id. The calculation is CONCAT("PSC";FORMAT(number;"000000")).

    In your product forms (eg, computer, printer), you would create a one-to-many relationship to the asset id form. Now whenever you click on the + icon (left most in the link-to-form table), a new product id is created.

    To get the asset id for the current product, I use following simple field script:

    function assetID() {
    
    	// field id of asset-id form link
    	const asset_ids_id = 'fld-xxx';
    	
    	// field if of asset-id in asset-id form
    	const asset_id_id = 'fld-xxx';
    
    	// get asset Ids records
    	let assetIds = record.getFieldValue(asset_ids_id)
    	
    	if (assetIds) {
    		// get asset id
    		let assetId = assetIds[0].getFieldValue(asset_id_id)
    		console.log("Asset ID: " + assetIds)
    		return productId;
    	}	
    }
    
    assetID();

    This script fetches the assetId field of the first asset record used in the one-to-many field (there should be only one…).

    Hope this helps to get you started!

    • This reply was modified 4 years, 1 month ago by Daniel Leu.
    • This reply was modified 4 years, 1 month ago by Daniel Leu.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #45464
    Kirk Williams
    Participant

    Greetings,

    Apologies in advance if I’m over-complicating things here (it’s something I tend to do often lol)…

    I am seeking suggestions for my initial forms structure. I’ve searched the forums extensively, but I’m having difficulty translating my situation into database-related terminology. The file I am creating is an asset inventory database consisting of items in various categories (computers, printers, devices, phones, keys, etc). The data is being migrated from GLPI (a PHP/SQL application), so it resides in a multitude of separate SQL/CSV tables. I’m fine with updating the source data in terms of translating IDs to text and restoring relationships, but I’m also looking to re-organize the inventory for use in tapforms.

    Essentially, every item has a unique identifier field, referred to as “ASSET ID”. This field is a simple sequential value ranging from “PSC000001” to “PSC002013”. What I haven’t been able to figure out is how (and if) I can continue using this identifier field while using multiple forms within the file.

    To elaborate: a “Computers” form would obviously have many different fields than a “Printers” form. What is the best way for me to use different forms for each, but to have BOTH forms use a single, related “Asset ID” field? I had considered taking a reverse logic approach in which all items were listed in a single form, but I’ve found that “hiding” fields that are not relevant to the device category is either not possible or is far beyond my scripting capabilities. I also feel this would negate many of the organizational benefits of using tapforms.

    I’m sure the first question many of you will ask is “why is it so important to retain this Asset ID field”… There are a few reasons I can offer, and I am 100% open to alternative suggestions:

    1. “Asset ID” has been used in our office for many years as the primary identifier for these items. It is incorporated into our ticketing and purchasing systems, both of which are outside of my control.

    2. The Asset ID (with barcode) is also pre-printed on our inventory labels that are applied to all newly purchased items. These labels are often scanned for use with clinical software, so they’re not going away or changing format any time in the near future.

    3. Obviously, it is imperative that the Asset ID is a UNIQUE value without any duplications. Less critically (but still important) is the need to ensure sequential numbering. The next new item added to our inventory should be assigned “PSC002014”, regardless of whether its a computer, a phone, or a television.

    I already sense that I’m rambling, so I’ll just leave this here and cross my fingers that what I’m asking makes sense. Thanks in advance for ANY suggestions anyone may have for a way to create this file without having to re-invent the wheel!

    Best,

    Kirk

Viewing 15 results - 1,111 through 1,125 (of 2,951 total)