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,066 through 1,080 (of 3,011 total)
  • Author
    Search Results
  • #46412
    JB Be
    Participant

    Fantastic. I filed my ‘duplicate’ question more than a year ago (see more upwards) and I am still in need of a solution, too. Thank you for taking this up, Sam. It all looks a little cryptic to me, though, being an informed user but not fluent in scripting…

    In my case, I am using the email-Adress as a unique identifier for 2000+ records. So I am looking for a (scripting) way to find records that have exactly the same email address in the specific field named ’email1′.

    In rare cases, there might be (erroneously) several email addresses in this field. In this case, I would look for records that have the same email address at least once in the specific field named ’email1′.

    Would you think the script above might help?

    #46410
    Brendan
    Keymaster

    Hi Chris,

    Yes, I could probably add a refresh function. form.refreshRecord(aRecord); would probably be a better API.

    I’m not sure if this would help you but there is an alternative setFieldValue() function:

    record.setFieldValue(movie_title_id, 'The Terminator', false);

    From the manual:

    Sets the value on the specified field and optionally executes scripts that would run by default when the field value changes.

    It also evaluates formulas too, not just scripts.

    #46408
    Chris Ju
    Participant

    Ok, wouldn’t have thought it is possible to write into a script field via script. Thanks for the great hint. Will try to implement it in the near future…

    #46402
    Sam Moffatt
    Participant

    Most of the time you can have an empty script field and it seems to work. There was one situation where for what ever reason it didn’t work for me and my work around was to just have the script do record.getFieldValue(scriptFieldId); which returns the value for itself. Since the value for the field is set by your other script field (e.g. record.setFieldValue(scriptFieldId, desiredFieldValue)) this should work properly. This is at the limits of what a script field should do but it does seem to work properly and gives you a read only field.

    #46399
    Chris Ju
    Participant

    Thanks, Sam, but what do mean exactly with

    “you can also work around that by using self referencing script fields that maintain their value set by an external script”?

    Do you have a short example?

    #46394
    Sam Moffatt
    Participant

    Chained fields is going to be complicated because how many times does the refresh need to be called to resolve everything becomes a recursion problem. How do you know when to stop evaluating if someone adds say a time based script that mutates each execution.

    A model I’ve used is having a single script that calculates everything and then stores the data in normal fields. There isn’t a read only option so they can be mutated by the end user but you can also work around that by using self referencing script fields that maintain their value set by an external script.

    #46393
    Sam Moffatt
    Participant

    Are you looking for exact duplicates (all fields identical) or duplicates on a primary or subset of key fields? If you want all fields identical, does this extend to link to form fields, table fields or photo fields and their contents?

    I was working a while back on tooling to do merging of records through the scripting interface to handle when I end up with duplicate shipping records due to key mismatch (sometimes the tracking numbers are changed in transit) but I never got it finished because the UI experience wasn’t something I figured out.

    If you’re after a subset of key fields, I did a quick POC where you create a new field in your source form with the key. I already had a composite key field built using a calculation field I use which looks like this (square brackets for field placeholders):

    IFEMPTY([Marketplace];"No marketplace";
    CONCAT([Marketplace], "/",[Store Name], "/",[Order ID]
    ))
    

    This creates what should be a unique key for the record based on my own metadata (designed to handle direct sales and hosted marketplaces). I then created a new form called “Orders Dedupe” and put in it three fields: a *string* type field called “key”, *link to form* field called “Order Dedupe” and a script field which counts the entries in the order. The link to form field is configured as a JOIN type on the “key” field of the dedupe form and the calculation field in the original form. The script field looks like this (change your ID’s to match):

    function Key_Match_Count() {
    	var order_dedupe = record.getFieldValue('fld-fde68e7d2b384cb2a4452d3ae66bbab1');
    	return order_dedupe.length;
    }
    
    Key_Match_Count();
    

    In this form also create a new saved search that uses the script field and is set to look for values greater than one as those will be the duplicates.

    Last step is to populate this form, go back to your base form and create a new form script. I wrote the script below to scan each record, use an md5sum implementation to create a hash of the key field and then look to see if that record exists in the dedupe form:

    document.getFormNamed("Script Manager").runScriptNamed("md5sum");
    
    var purchase_key_id = 'fld-3e49aaa5bc32429c8f0f0f234878356d';
    var dedupfield__key_id = 'fld-c52906ee940142a0a54fac1a98346afd';
    var dedupForm = document.getFormNamed("Order Dedupe");
    
    function Extract_Purchase_Keys() {
    	for (let sourceRecord of form.getRecords()) {
    		let purchaseKey = sourceRecord.getFieldValue(purchase_key_id);
    		if (!purchaseKey) {
    			console.log("Missing purchase key for record: " + sourceRecord.getUrl());
    			continue;
    		}
    		let purchaseKeyHash = "rec-" + md5(purchaseKey);
    		let dedupRecord = dedupForm.getRecordWithId(purchaseKeyHash);
    		if (!dedupRecord) {
    			dedupRecord = dedupForm.addNewRecordWithId(purchaseKeyHash);
    			dedupRecord.setFieldValue(dedupfield__key_id, purchaseKey);
    		}
    	}
    	document.saveAllChanges();
    }
    
    Extract_Purchase_Keys();
    

    This actually found me a dupe record that I hadn’t found in my orders form when I went back to look at the saved search. It’s a bit of a journey, might turn it into a video at some point when I get some more time.

    #46391
    Bert Rietveld
    Participant

    I have over 84,000 records. Sorting and manually scanning would not work. Is there a script to find duplicates?

    #46390
    Chris Ju
    Participant

    I just resolved the automatic refresh of all required fields (with all their dependencies) just by changing the order of the fields and adding an if-loop to each of the calculation fields and the script field. Now i can click the “+>”-Button and all fields are refreshed without hitting CMD-R.

    BTW: I had also the idea to merge the calculation fields to the script field, but i don’t know if this will do it (at the moment i haven’t the time to “translate” the formulas to javascript)…

    @Brendan: Isn’t possible to add an function like << record.refreshRecord(recordID) >> which will do the same as CMD-R?

    #46387
    Chris Ju
    Participant

    Hello,

    i’m trying to refresh a new child record which i created with ‘record.addNewRecordToField’ in background.

    I just don’t want to double click the new entry and press CMD-R. In the related child form there a some script and calculation fields. The problem is, that calculation 1 has an result for calculation 2 and these both has a result i use in a script field.

    At the moment i have to open the new record and press three times CMD-R. This isn’t so funny that I want to do it 100 times a day…

    I couldn’t find something in the javascript documentation to trigger the refresh with a script…

    Had anyone had the same problem and have a solution?

    Thanks a lot…

    #46382
    Daniel Leu
    Participant

    Maybe using web links instead of ‘alias attachments’ might be an option. Usingfile://nas_mounted/path/to/file.pdfas theURLopens the file, assuming that the directory is selected asScript folder access in the preferences.

    In one of my uses where I have to link to several files, I use a table. Each row will point to a separate file.

    In Finder, if you ctrl-click on the filename and then press the alt key, you can copy the pathname for the file. Then you can use a simple form script to set the URL field based on the just copied pathname using Utils.copyTextFromClipboard()

    • 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

    #46379
    Sam Moffatt
    Participant

    The files themselves have the same name and extension of the target but the contents are the secure bookmark metadata so double clicking on it directly won’t work because the file needs to be resolved by the owning application (in this case Tap Forms) which then opens the actual file. Finder doesn’t seem to handle this, I ran into this when I was toying with things trying to figure stuff out.

    I was looking at the file, it should have the metadata needed to reconnect the file assuming the paths are the same but I guess the security store (TCC maybe?) needs to validate it or something.

    If you do the add, it’s just a copy. If you update the NAS file you need to delete it from the Tap Forms document and re-add it. Maybe with a newer version (TF6?) an expanded scripting API for interacting with the local file system might work where you could detect that and process it. I think you can sort of do some of it today but it’s more geared towards web stuff.

    #46327
    Tim Greenwell
    Participant

    Is it possible to insert a chart into a layout? Ideally the chart would be fully customizable, even if that requires drawing it with javascript.

    Thanks for your advice!

    #46322
    Andreas .
    Participant

    Hi,

    how is it possible to know the name of a field in the layout mode ?

    In some layouts I prefer to delete the description field in some cases or I might loose the information field by dragging the fields around. In this cases I am not able to identify the fields anymore.

    I would expect this information in the inspector sidebar.

    best
    Andreas

    #46315
    Brendan
    Keymaster

    Hi Eddy,

    Thanks for the feature request.

    You can trigger the Print screen from a Script.

    Utils.printRecordsShowPanel(true);

    But you can also select a layout first:

    document.selectFormLayout(form_id, layout_id);

Viewing 15 results - 1,066 through 1,080 (of 3,011 total)