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,471 through 1,485 (of 2,952 total)
  • Author
    Search Results
  • #43384
    ArsAstronautica
    Participant

    This seems the right place to ask. What I’d like to do is to have Siri search for a trimming that is in a particular field database file or field. I have a data base of things and if I’d like to be able to look something up and have Siri read back the item.

    By way of simple example, say I have a database of widgets. “Hey Siri what is the size of widget # 37”. The shortcut would tell Siri to look in file xyz.db in the # field and return the size field.

    That seems to be doable in AppleScript (I think), but I’de like this as a iPhone/iPad shortcut of course.

    #43382

    In reply to: Fuzzy Dates

    Doug Bank
    Participant

    Thanks! So if I choose to go this route, I need to be careful with the date format. I am currently using Jan 26, 2018 as I described above. It looks like this script will now use 20180126, which isn’t easily readable. Or am I getting the syntax wrong?

    It would be nice if it was readable and sortable, and these seem to sort correctly: 2018/01/28 and 2018 and 2018/01? Still kind of ugly, though. Is there any reason to use – instead of / or do special characters not have any hidden meanings?

    #43381

    In reply to: Fuzzy Dates

    Daniel Leu
    Participant

    I suppose I could just use a text field, but even that would be annoying because if I convert an existing Date field to a text field, the data is erased. I already have 200 records, so converting to text would require me to cut and paste the existing date 200 times.

    You could use a form script to translate the date field into a text field.

    Following script would do that. You just need to update date_id and text_date_id to match your form.

    
    function Convert_Date() {
    
    	var date_id = 'fld-f74f442f93b7499aba86170cbab5e3a1';
    	var text_date_id = 'fld-87e6c288a4e042c1bbfff27849a4b224';
    
    	// loop over all records
    	for (rec of form.getRecords()){
    		let date = rec.getFieldValue(date_id); // get date
    		if (date){ // if date exists
    			let textDate = date.toLocaleDateString("en-US", { year: 'numeric', month: 'numeric', day: 'numeric' }); // create date string
    			console.log(textDate);
    			rec.setFieldValue(text_date_id, textDate); // store date string
    		} else {
    			console.log("Empty date");
    		}
    	}
    
    	document.saveAllChanges();
    
    }
    
    Convert_Date();

    Cheers, Daniel

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

    #43361

    In reply to: Latest Date

    T.L. Ford
    Participant

    That’s awesome! I’m so glad!

    The scripting is powerful, but it also has a fairly steep learning curve. I have an intro to scripting here: http://cattail.nu/tap_forms/tap_forms_scripting_101/index.html

    – T

    #43355
    Brendan
    Keymaster

    Great explanation Sam.

    At some point I would like to add triggers to run Form Scripts based upon a specific set of events. I know you asked for this eons ago Sam.

    #43353

    In reply to: Latest Date

    T.L. Ford
    Participant

    A script field would work.

    var when_id = 'fld-a13ae3e64dd340138d08e719fe2a9aa9';
    var childform_id = 'fld-8ead2e10d2634bd4925175d72f943857';
    
    function Max() {
    
    	var arr = record.getFieldValue(childform_id);
    
    	arr.sort(compare);
    	
    	return arr[0].getFieldValue(when_id);
    }
    	
    function compare(a, b) {
    
      if (a.getFieldValue(when_id) > b.getFieldValue(when_id)) {
        return -1;
      } else if (b.getFieldValue(when_id) > a.getFieldValue(when_id)) {
    	  return 1;
      }
      return 0;
    }
    
    Max();

    You will need to get your field ID’s.
    Make sure you set the return results type to Date.

    #43351
    Sam Moffatt
    Participant

    Calculation and Script fields are automatically run each time a field they reference is updated within a record. A script field can then change other fields in the record as well which can optionally also trigger scripts that watch those fields (a behaviour that can be disabled if needed to avoid cycles or other behaviour that might not be intended). Calc and script fields are also evaluated when a record is created.

    Form scripts are executed on demand and you can execute them against the currently selected record (in which case record is populated) or you can apply it to all records in the form (form is populated which has a getRecords() method). There is also another special search variable that is populated when you’re working with a search (you can do typeof(search) !== "undefined" to see if it is set).

    #43349
    Keith Nolen
    Participant

    Hi! Is there a way to run a script on a record change or save event? And can I modify just one record with a script, or does a script have to modify all records in a form?

    What other events are there?

    #43325
    T.L. Ford
    Participant

    As a long-time Access dev, I can say that Tap Forms is the closest database I’ve found for a native Mac platform, and I really like it. There’s some “adjusting” to do to learn how to make relationships (linked fields) as it is a no-sql database, and scripting is via JavaScript, not VBA (but the “there are objects/properties/methods” is the same). If you are importing relational data, you can expect to go through a bit of a learning curve for making the fields link in the converted data. Form design is different than in Access and I’ve just gotten used to using the defaults. Notably: Form == Table in Tap Forms, so you can find both the form and the table design together. Multi-user security is not as robust as Access. Photos (and other “extended” field types) are much nicer in Tap Forms.

    #43310
    GLS
    Participant

    Thank you very much for your help!

    I edited the script so that it has the proper IDs but I get the following error message in the console:

    Invoicing: TypeError: document.getFormNamed("Consultations").getSearchName is not a function. (In 'document.getFormNamed("Consultations").getSearchName("Uninvoiced Consultations")', 'document.getFormNamed("Consultations").getSearchName' is undefined), line:(null)
    

    I also tried with simple quotes ‘ ‘ without success.

    #43300
    Daniel Leu
    Participant

    There are many ways to convert a date object into a format string in Javascript. Following works for me:

    var date = record.getFieldValue('fld-xxx');
    console.log(date.toLocaleDateString("en-GB", { year: 'numeric', month: 'long', day: 'numeric' }));

    Console:
    January 21, 2021

    Cheers, Daniel

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

    #43299
    Victor Warner
    Participant

    In my form I have a number of fields of the date type with a date format of long (that is 27 January 2021). In a script I have included the date field, but the output is as follows: “Wed Jan 27 2021 00:00:00 GMT+0000 (GMT)”, for example:

    var hedd_verification = record.getFieldValue('fld-e7c386b5203a456dbaeb4755c6897a23');
    var hedd_verification_id = 'fld-e7c386b5203a456dbaeb4755c6897a23';
    
    var degree_level = record.getFieldValue('fld-04d88b9bf5c34cef8b2b488e4bccd67d');
    var degree_subject = record.getFieldValue('fld-e1c8f4bdea994a149cc338498c22e20e');
    var hedd_date_verification_sought = record.getFieldValue('fld-db9621fa80094bb9ac4fc2f68bcc2595');
    var hedd_date_verification_obtained = record.getFieldValue('fld-b7c0b62ed0514a15848e8cb32262b617');
    var gender = record.getFieldValue('fld-e6697b5fc0d24f328757592bf4362d4e');
    
    if (hedd_verification == 1) {
    
    	"and I verified that " + gender + " was awarded the " + degree_level + " in " + degree_subject + " by contacting HEDD (www.hedd.ac.uk, who are 'UK Higher Education's official service for candidate verification and university authentication') on " + hedd_date_verification_sought + " and receiving confirmation from HEDD of the award on " + hedd_date_verification_obtained
    } else {
    
    "but I have not verified that the degree certificate is genuine nor have I made any independent check as to its authenticity"
    }

    Is there a way to format the date in the script so that the date comes out as 27 January 2021 rather than “Wed Jan 27 2021 00:00:00 GMT+0000 (GMT)”?

    Any help would be gratefully received.

    #43293
    Daniel Leu
    Participant

    Here is the same code again but this time it uses the new javascript iterator map:

    function Childs() {
    
      // get all child records
      var childs = record.getFieldValue('fld-c22501cc3910474aa1c59387fde30d82');
    
      // define id of name field of the child form
      let childNameId = 'fld-8b8f3b0cd59b4b4c9180a8903685e7ee';
    
      // get child names in a array
      let childNames = childs.map(function(i){ return i.getFieldValue(childNameId)});
    
      // return child names as a comma separated string.
      return childNames.join(', ');
    }
    
    Childs();

    Cheers, Daniel

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

    #43290
    Eddy
    Participant

    Hi Folks!

    I have a (hopefully) small issue …

    In order to categories records, I use a many-to-many relationship. This allows me to change the names of the categories later, because the category name is the value of the first field in the related record. And in the related record I can see easily a list of all records, with are under a specific category. So, this is the advantage compared to a picklist.

    But now I need to read out the category-names, so that I can use them in the mother record. Concrete, I want to script, so that I have a text field, with just list all the category names a specific record belongs to.

    So, call my stupid, I find no way. Of course, I know how to import a field value from a related record. But how can I get a list of all the field values in the first field of all the records wich are related?

    Thanks in advance, all the best, stay healthy!

    Eddy

    #43262
    Sam Moffatt
    Participant

    Play with the link structure and how it works in the UI is probably my best suggestion there to get through what flow works best for your processes. One other aspect I’d add is that if you can tackle some Javascript, it can make working with linked fields more efficient. A simple example is that I have a form script that triggers a prompter to quickly input a subset of the data or fields without having to leave the parent form (particular use case is entering shipping data, it also sets the ship date to the current date plus some other nice features).

    On the second part, you just create a link that is file:///Users/username/path/to/folder/ in the website field and when you click on the globe it should trigger Finder for you. If you put the full path in, it should trigger selecting the file in the Finder window (I don’t think it’ll open as a security limit from MacOS).

Viewing 15 results - 1,471 through 1,485 (of 2,952 total)