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,531 through 1,545 (of 2,989 total)
  • Author
    Search Results
  • #43204

    In reply to: All records printing

    Gregory martin
    Participant

    I am pretty sure (happily be corrected here), that there is no reporting mechanism in TapForms. It is a single table data collection tool rather like dBase or Foxpro and while it does have one2many capabilities it has no “list records” function as such, although you could do this in a Script.

    I personally use the export and then analyse my research in Excel. This does mean having to join my relationships again of course, and I am considering Report Studio for iMac to help with this, but it is a touch pricey just for now.

    #43201
    Sam Moffatt
    Participant

    For the moment that’s why I suggest using a bridge, MacOS ships with Apache and PHP out of the box that can be relatively easily enabled and Homebrew can be used to upgrade versions if that doesn’t work. PHP gives you access to it’s APIs for making HTTP requests as well as the ability to use libcurl to make requests for anything more complicated. Obviously if PHP isn’t your thing there are other options for building a web server that provides a bridge between TF and the services you need to interact with. For myself I have a bunch of PHP scripts that handle this using curl to add in extra headers or options that TF doesn’t permit some even provide a caching layer to avoid redundant requests.

    In the long run I think if there were a JSC implementation of Fetch that could be added that’d be great but I don’t see anything. I feel leveraging an existing spec makes sense because it provides a framework of what needs to be built and a suggestion for an API. The closest I found was a gist with some code in it but far from a full implementation.

    #43198
    MRAnderson
    Participant

    I need to tell my envelope layout to slide the city/state/zip line up if the second address line (apartment or suite #) is empty. Looking for help online, I am finding ways to script this, and I have tried to follow the instructions to no avail. I know I’m doing it wrong. I didn’t expect to need programming skills (I know, they’re basic, but still above me) to use this app, which I love otherwise. Please help!

    FYI, my layout fields are “address name”; “address A1” (street address for primary residence); “address A2” (suite or apartment #); and “csz” (city/state/zip). (I don’t need separate fields for these in my anticipated use, so there’s no horizontal-slide issue, just vertical.)

    Thank you!

    #43192

    In reply to: Custom ID Numbers

    Doug Bank
    Participant

    So these scripts don’t handle the creation of ID numbers, but they keep watch behind the scenes to make sure that the IDs are never accidentally duplicated?

    #43188

    In reply to: Custom ID Numbers

    Gregory martin
    Participant

    Here is a more compact version. Sets the script field to 1 if exists or 0 if unique.

    var mainfield_id = 'fld-d5dba46d240d4d41bd792970526b5bc9'; // change this to your field ID
    var newvalue = record.getFieldValue(mainfield_id);
    var thisrecord = record.getId();
    checkunique();
    function checkunique() {
    unique=0;
    var records = form.getRecords();
    unique = 0;
    for (var index = 0, count = records.length; index < count; index++){
    	// do not check current record
    	if (records[index].getId()!=thisrecord) {	
      	    // check other record values for duplicate
        	if ((unique == 0) && (records[index].getFieldValue(mainfield_id) == newvalue)) {
        	   unique=1;
               console.log("Already exists");
               break;
            }     
            return unique;  
    }}};
    #43184

    In reply to: Custom ID Numbers

    Gregory martin
    Participant

    You could check a field for being duplicated by adding this to a script field on your form, and the script is triggered when you press enter on the field you specify in the mainfield_id. Not sure how fast this would be on thousands of records though! You need to change your id for the field your are checking. This code snippet writes out ALREADY EXISTS in the console, otherwise the values of the records, so amend as needed of course

    // ***** this needs to be your field ID
    var mainfield_id = 'fld-d5dba46d240d4d41bd792970526b5bc9';
    // ===========
    
    var newvalue = record.getFieldValue(mainfield_id);
    var thisrecord = record.getId();
    checkunique();
    
    function checkunique() {
    unique=0;
    var records = form.getRecords();
    unique = 0;
    for (var index = 0, count = records.length; index < count; index++){
        // ***************************
    	// do not check current record
        // ***************************
    	if (records[index].getId()!=thisrecord) {
    	
      	   console.log(records[index].getId());
      	   console.log(records[index].getFieldValue(mainfield_id));
      	   console.log(newvalue)
      	   
      	    // check other record values for duplicate
        	if (records[index].getFieldValue(mainfield_id) == newvalue) {
               console.log("Already exists");
            }       
    }}};
    #43183

    In reply to: Custom ID Numbers

    Sam Moffatt
    Participant

    The Tap Forms built in autoincrement option for numbers shouldn’t duplicate even if you delete a record, the autoincrement count will increase. You could use a calc field to copy it across but in reality if you hide it then it is likely enough. The exception is if you use sync and multiple devices because each device might not be aware of the other and new records on both devices might duplicate an ID.

    You can use a form script to override a value of the calculation field if you need to regenerate it later. Almost every field type can be modified by the scripting engine (exception being created date, modified date and modified by device), so realistically nothing is truly read only.

    #43176
    Doug Bank
    Participant

    I am building a form to document a collection. I would like to have a field that captures an ID number that will be used to physically mark the item in the collection so that I can easily identify it and look it up in the future. Brendan has told me how to use an auto-incrementing number field for this purpose, but I foresee some issues.

    I would like the field to include a prefix and possibly a custom suffix. I figure that I can have a hidden auto incrementing number, and then use a script to concatenate the prefix and suffix to the ID number and then only display the result. However, I don’t know how to create such a script, and even when I do it, I want it to show 5 digits, which the number field doesn’t like.

    For example, one possible ID NUmber could be DJB00345-F

    Does anything like this exist, or do I need to figure out how to script?
    Is there any way to ensure that the numbers will never change and never be duplicated?
    What happens if I create a new record by accident and then delete it. Will that ID number be gone and unused forever?

    Thanks,
    Doug

    #43147
    Sam Moffatt
    Participant

    Glad to hear you got it to work, if it solves the problem then there’s no issues using it.

    Ternary operators is something I’m personally quite fond of and in a language like Javascript where it’s more flexible with typing it also covers a variety of situations. Since Javascript will convert anything into a boolean based on if it’s truthy or falsy, it means a bunch of values that we aren’t interested in (empty string for example) are covered by the statement too.

    One note, don’t confuse “Java” with “Javascript” because whilst they seem like they should be related, it was really a marketing ploy. There are plenty of web focused Javascript resources (Mozilla Developer Network, W3Schools) and a few resources leveraging node.js (also W3Schools as an example), there aren’t that many resources that focus on pure Javascript that I’ve found. A lot of the resources include platform specific stuff that really only relates to the use in web browsers or to node.js rather than the ECMAScript standard.

    #43142
    Sam Moffatt
    Participant

    The script I wrote doesn’t use the default template with the function, it’s just that text in the script editor. I’ve attached a screenshot of what it looks like to make it clear. When you’re dealing with something simple it’s sometimes easier to just directly put the code into the editor without the extra wrapping. In this case where we’re essentially doing a single line calculation, we can simplify a little :)

    To get your code to work put a return in front of the self ? self : modified; line. Taking what you’ve got though, something like this should make it work:

    function User_Script() {
    
    	var self = record.getFieldValue('fld-36b6432d2ec640c29f48daf7c45b74ae');
    	var modified = record.getFieldValue('fld-ac2a6fe2490e464bb4ff32ef723e6a8b');
    
    	console.log (self);
    	console.log (modified);
    
    	return self ? self : modified;
    }
    
    User_Script();

    Minor reordering to put the console.log line ahead of the return and then an explicit return from the result of the ternary operator. The operator is a short hand for doing the following instead:

    if (self) {
       return self;
    } else {
       return modified;
    }

    What it’s doing is essentially simplifying that down to a single line instead of the five lines (and the word return written a couple of times).

    So no boilerplate?

    Fundamentally you don’t need the function wrapper, it’s there because without it you can’t use the return statement. When we don’t use the function boilerplate that Tap Forms provides and write directly in the script (as depicted in the screenshot), the return statement doesn’t work because there is no function to return from. This is another reason to use the ternary operator as it helps out making things a little compact. The alternative looks a little weird to most Javascripters:

    if (self) {
        self;
    } else {
        modified;
    }

    This works but looks a little awkward because well you’d expect a return statement however because this is capturing the last value from the script directly you don’t need the return. In fact the runtime will give you an error if you put a return statement in saying “Return statements are only valid inside functions.”

    Attachments:
    You must be logged in to view attached files.
    #43138
    Stephen
    Participant

    Hi Sam,

    thanks for the reply.

    Everything you said makes sense, but it’s not working in practice in my world :(

    User_Script();
    
    function User_Script() {
    
    	var self = record.getFieldValue('fld-36b6432d2ec640c29f48daf7c45b74ae');
    	var modified = record.getFieldValue('fld-ac2a6fe2490e464bb4ff32ef723e6a8b');
    
    	self ? self : modified;
    console.log (self);
    console.log (modified);
    
    }
    
    User_Script();

    I don’t understand the syntax of the “self ? self : modified;” line.
    I understand your description of how it should work, but have I missed something, as I get no value in the field. I added the console log lines & the console shows the expected values.(Undefined & my MacBook name).

    Thanks, Stephen.

    #43137
    Sam Moffatt
    Participant

    I don’t see the modified by field in the script editor link, however you can grab the field ID from just under the description field in the field editor panel. You can then use that with record.getFieldValue and that seemed to work properly for me to retrieve the value that I expected in the quick test I did. There might be a way of convincing a calculation field to get at it, but for myself I use a script field for this particular purpose.

    You can also cheat with a script field and use it to set the value automatically:

    var self = record.getFieldValue('fld-991082c160224a12a87151cf87aaec93');
    var modified = record.getFieldValue('fld-b7b336c4acc7406786eecc8a7b9f75b9');
    
    self ? self : modified;
    

    Where self is the ID of the script field you just created and modified is the ID of the modified by field you created. Essentially it says if self is set, use the value of self otherwise use the value of modified. Tap Forms takes the return value of this to update the value of the script field so that the next time it’s run, it uses the value of the script field. This makes the field read only in a way that can’t be edited without having to use another script field or form script to change it. An example form script would look like this:

    function Reset_Created_By() {
    	record.setFieldValue('fld-991082c160224a12a87151cf87aaec93', undefined);
    	document.saveAllChanges();
    }
    
    Reset_Created_By();
    

    Which resets the field value to an empty value which then triggers the form script to reset the value to the current value of the last modified device. We need the document.saveAllChanges() here to tell Tap Forms to save the change made by setFieldValue. We didn’t need it on the script field because Tap Forms is implicitly saving the result of the script field.

    Hopefully this helps!

    #43136
    Sam Moffatt
    Participant

    I don’t think you can make the field mandatory (though Brendan will likely correct if I’m wrong there) however I’d use a script field to check to see if the field is empty. Create a new script field in your child form, jump into the script editor, keep the function template but wipe out the contents of the method, double click on the section heading matching the name of the field and it’ll put in a record.getFieldValue line then you can check if it’s undefined or not. Something like this worked for me with a test form I was using:

    function Missing_Parent() {
    	var days = record.getFieldValue('fld-429746c8ec6d433d9bb1247a5ddf31bf');
    	if (days === undefined) {
    		return 1;
    	} else {
    		return 0;
    	}
    }
    
    Missing_Parent();
    

    I set the field return on the left of the script editor to be the number type and then you can do a saved search on that field to look for one or zero. You can hide the script field once this is all working to clean up your form display.

    I can reproduce the bug with creating a new parent from the child doesn’t unlink the old parent from the child.

    #43134
    Stephen
    Participant

    Hi,

    I’m a real newbie at related databases period, but with help I’ve had some success & I’m understanding more, but I have another issue that after much time searching these forums, reading the 101 & 102 etc. and many attempts is still not coming right, so a steer would be really appreciated.

    I’ve created a new form for notes as a child of the main form using a 1:many.
    I’d like to track who created the note record & who last made a modification to it.

    The later is solved easily with the Modified by device field type, but I’m struggling to set the original creator with a fixed value. My original thinking was a calc or script that tested if a text field for “Created by:” was empty and referencing the Modified by device value if empty & ‘undefined’? if not?

    It doesn’t seem possible to reference that field type within a calculation or script, at least not in a way that appears obvious to me?

    Do I need to think about this in a different way?

    Thanks, Stephen.

    #43084
    Stephen
    Participant

    Ok, my bad…

    RTFM!

    The answer is here all along… Tap Forms Scripting 101.

    So there are two types of scripts… I had created mine in the wrong place. It is now made as a field script. So answered half of my own questions. D’oh!!

    Now, if I can just find out how to return the record colour to default appearance…
    I’ll keep looking until someone can chip in with a clue, maybe I’ll be back to solve my own issue again! lol

    Doing some serious learning today! ?

    Stephen.;)

Viewing 15 results - 1,531 through 1,545 (of 2,989 total)