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,636 through 1,650 (of 2,989 total)
  • Author
    Search Results
  • #42420
    Sam Moffatt
    Participant

    Part of the reason I started to do the videos is that there isn’t a lot of Tap Forms specific content out there and whilst it’s vanilla JavaScript in a strict sense, it’s also obviously a specific API as well. There is something in a video where seeing everything step by step can help expose something that written documentation sometimes misses pieces that are thought to be understood. The videos I try to record in a single take without editing so as to not lose anything which also means real surprise when things don’t go 100% to plan. That’s also useful in my mind because it helps to show what can go wrong, at least a few things anyway (or just my own confusion at my own copy paste).

    Videos are of course inspired by what I see in the forums. I’ll take a chop at looking at a copying video and hopefully it can help. I’m hoping to slowly build up a library of a bunch of different recipes for solving problems for folk so that eventually it’s got a little bit of everything.

    I think what @cattailnu is doing with the tutorials is a great place to start and if you spend some time on the regular JavaScript tutorials it can help as well even though they’re generally browser focused or Node.js focused.

    That said I did a quick Google search and I think this might help as well:

    • Mozilla’s JavaScript documentation is great albeit focused on web based usage of JavaScript at times. They’ve got one of the more detailed references and if you don’t mind picking up some other web stuff (HTML/CSS), then it’s the traditional way to learn JavaScript.
    • Apple’s Mac Automation Scripting Guide has some JavaScript references but it’s pretty light, even pointing to Mozilla’s site for JavaScript.
    • Beginners Guide to JavaScript for Automation looks a little more at the script editor and how to use it with JavaScript, a similar environment to Tap Forms.
    • Looking for JXA resources also took me to a page with JavaScript for Automation resources linking to a bunch of different pages.

    We do need more resources dedicated to scripting in Tap Forms and getting folk up to speed. I’m looking forward to TF Scripting 103 helping to expand documentation base further too :)

    #42415
    Sam Moffatt
    Participant

    Yes, it should be ~/Library/Application Scripts/, not sure where that got rewritten in the first part of the reply, later on it has the correct path.

    I guess I cleaned up one too many things, just add this back after the End Sub:

    Public Function GetLength(a As Variant) As Integer
       If IsEmpty(a) Then
          GetLength = 0
       Else
          GetLength = UBound(a) - LBound(a) + 1
       End If
    End Function
    

    That should fix that other error up as well.

    #42412
    Brendan
    Keymaster

    Hi Mauro,

    Yes, this is possible.

    You’ll need to write a Script field for it using this code:

    
    function getTotal() {
       var number_field_id = 'fld-....';
       var total_number_field = form.getTotalOfField(number_field_id);
       return total_number_field;
    }
    
    getTotal();
    

    You have to provide the proper ID value for number_field_id for your form’s Number field of course.

    Set the Return Type of the Script to be Number.

    #42408
    Chris Ju
    Participant

    I tested the files, but i get an error (see screenshot).

    Are you sure i have to put TFIntegration.scrpt into

    ~/Library/Application Scripting/com.microsoft.Word?

    The correct location is maybe

    ~/Library/Application Scripts/com.microsoft.Word

    Attachments:
    You must be logged in to view attached files.
    #42404
    Sam Moffatt
    Participant

    Ok, ended up figuring out an approach to this but it’s a little slow (I can see the copy and replace operations as they happen). I think this is due to leveraging AppleScript to process the query string pieces.

    To solve this I went digging for a more comprehensive URL decode method that handles the strings properly and ended up settling on using NSString’s stringByRemovingPercentEncoding however that requires creating an AppleScript file and put it into ~/Library/Application Scripting/com.microsoft.Word so that we can get to it from Word VBA.

    Here’s the AppleScript I saved as ~/Library/Application Scripting/com.microsoft.Word/TFIntegration.scpt (you might need to create the directory, it didn’t exist already for me):

    use framework "Foundation"
    
    on decodeURIComponent(encodedString)
    	set tempValue to stringWithString_(encodedString) of NSString of current application
    	set decodedValue to tempValue's stringByRemovingPercentEncoding
    	return (decodedValue as string)
    end decodeURIComponent
    

    Basically all we’re doing here is creating a NSString object, run it through NSString’s stringByRemovingPercentEncoding, turning it back into an AppleScript string and handing it back to the caller (in this case our Word VBA script).

    Calling this from VBA ends up looking like this:

    Public Function ASURLDecode(inputValue As String) As String
        ASURLDecode = AppleScriptTask("TFIntegration.scpt", "decodeURIComponent", inputValue)
    End Function
    

    Again this is expecting a file named TFIntegration.scrpt to be in ~/Library/Application Scripts/com.microsoft.Word to work properly. You might want to open it with Script Editor on your Mac to make sure MacOS doesn’t grumble about it being from somewhere else it doesn’t like.

    I found another example of finding and replacing text that’s more comprehensive and seems to solve the header/footer problem in my testing. I did some changes to it and I’ve updated the autoscript.bas file with the changes. I did some clean up to remove the older method which if someone is only dealing with ASCII characters are much quicker.

    In the attached zip is an updated copy of the template including header/footer placeholders and the VBA script, as well as a copy of the TFIntegration.scpt file though you might need to recreate this because of how Apple’s sandboxing code works (scripts are protected). You might need to open it or do something funky. In my searches there was references to AppleScript files not being picked up properly unless there was a restart of the entire Mac, I didn’t have to do that but as a part of this I did see the error and restarted Word a few times which seemed sufficient.

    Attachments:
    You must be logged in to view attached files.
    #42402

    In reply to: Empty Date gives 1970

    Sam Moffatt
    Participant

    The Unix epoch is January 1st, 1970. Dates in a number of systems are stored as relative to that date, either as seconds (Unix compatible systems including MacOS and Linux) or as milliseconds (Javascript). Zeroth time if you will is that date.

    #42391
    Sam Moffatt
    Participant

    So record.getFieldValue() accepts a Tap Forms field ID and will return a variable with contents of that field for the currently selected record. In your example, Dem isn’t declared so you need to define it.

    On the left panel of the script editor should be a list of fields, click on your “Dem” field (I’m making a guess here) and then the little “ID” button should insert something like:

    var dem_id = 'fld-1234';
    

    I see you want to reference a phoneDem field as well, insert an entry for it, I’m going to assume it looks something like this:

    var phoneDem_id  = 'fld-4321';
    

    Now you’ve got the variable set up, you can then use this to get the value of the field:

    var dem = record.getFieldValue(dem_id);
    

    This gets the value of the field and puts it into the variable dem which you can then check to see if it matches your value:

    if (dem == "Yvon Lainé")
    {

    It looks like you’re trying to set a value back, so to do that you need to use record.setFieldValue. The first parameter is a field ID and the second is the value you want to set. You also need to tell Tap Forms to save your changes as well with document.saveAllChanges():

        record.setFieldValue(phoneDem_id, "06 xx xx xx xx";
        document.saveAllChanges();
    }


    @cattailnu
    on the forum has a Tap Forms JavaScript Scripting 101 that might help you get started as well.

    #42390
    Sam Moffatt
    Participant

    The currently selected record is generally record, so to delete it you just need to do form.deleteRecord(record).

    There are some times this isn’t true, particularly when working with the script editor and link to form fields, but for simple documents it should always be true.

    #42389
    Sam Moffatt
    Participant

    Ok, so I did the video recording and uploaded it to YouTube which walks through creating a new form, creating the script for it, a short diversion to talk about script folder access for scripting, checks out the Word template mentioned above and shows how to grab the template file to populate data from the clipboard.

    Here’s the script used in the video:

    function Word_Template() {
    	var first_name_id = 'fld-02f5c873bbdf499595b11624a525d616';
    	var last_name_id = 'fld-b79a9795b4b4426594be58027c21f9a8';
    	var prize_id = 'fld-b620679ff7024a309ef67624bb8e5ea0';
    	var transfer_amount_id = 'fld-30891550250d41d7aa087c87baa7ee9c';
    	var transfer_method_id = 'fld-3151d0fa67b342f0ad2c9e4bfbc98197';
    	var address_id = 'fld-b424d8e5a1d041baa91ed2823bcc2727';
    	var signature_name_id = 'fld-a84db7c9468b41689e6b102938b3c391';
    
    	var fieldMap = {
    		"FirstNamePlaceholder": first_name_id,
    		"LastNamePlaceholder": last_name_id,
    		"PrizePlaceholder": prize_id,
    		"TransferAmount": transfer_amount_id,
    		"TransferMethod": transfer_method_id,
    		"AddressPlaceholder": address_id,
    		"SignatureName": signature_name_id
    	};
    
    	var queryString = Object.keys(fieldMap).map((key) => {
    	    return encodeURIComponent(key) + '=' + encodeURIComponent(record.getFieldValue(fieldMap[key]))
    	}).join('&');
    	
    	Utils.copyTextToClipboard(queryString);
    	
    	Utils.openUrl("file:///Users/pasamio/Library/Containers/com.tapzapp.tapforms-mac/Data/Documents/TFTest.dotm");
    }
    
    Word_Template();
    

    Attached is also a copy of the exported Tap Forms archive with the Word Contacts form with Word Template script plus a bonus sample record included. Not the greatest integration point but I think should be more or less functional.

    I think if we were on Windows, it’d be a little easier to interact with tooling because you could use COM to invoke an instance of Word and manipulate it more directly, instruct it to save somewhere and then pull the document in. Microsoft’s tooling on the Mac has lagged and one can’t entirely blame them as it is the competition. I’m not aware of any direct mechanism for integrating with Word on Mac which doesn’t require use of either AppleScript or Microsoft’s own Visual Basic for Applications.

    Riffing on this, one platform that I have interacted with before is OpenOffice/LibreOffice UNO which allows programatic access to documents stored in it’s format. The downside of this is that you need to ship or have accessible on the network an instance of OpenOffice/LibreOffice to do the heavy lifting (~250MB download vs ~60MB for Tap Forms uncompressed). That would allow the creation of Word documents that could be attached but would obviously require users to download it.

    #42388
    T.L. Ford
    Participant
    #42387
    Brecht DHeere
    Participant

    Hi, when I run this script all the records are deleted in that form. I only want to delete the selected record. How can I do that?

    #42386
    Michael Mckenna
    Participant

    Hi, I have been using TF5 for the past 2 months and am really enjoying a lot of the very basic elements making forms. The problem is my knowledge of scripting is zero and so I am very limited with what I can achieve. I have looked online and trawled the forums and it seems its all or nothing, it took me 2 days to find “\r” to add into a script so I could add text to the line below. The next thing is getting information from one form onto another, in my mind that should be relatively easy but I cannot find a basic tutorial on how this is performed, explaining in simple language how this is achieved.The examples don’t have to be complex just simple enough so people like me can build on a foundation. I have seen some of Sam’s videos on YouTube and they are a good start but they are still assuming people have an understanding of writing a script. I have also been trying to find detailed info on snippets with examples and clear explanations on what each one does.I know this is sounding like a whinge but I am loving this app and want to get the most out of it. Interested in your thoughts. I hope this is taken in a positive way as it is not intended otherwise.

    #42385
    Christian Rommens
    Participant

    I am using the trial version of Tap Form. I wrote this first simple script but it doesn’t work. Could you tell me the error please :

    function Phonedemarcheur() {
    record.getFieldValue(Dem);
    if (document.form.Dem.value = “Yvon Lainé”){
    document.form.phoneDem.value = “06 xx xx xx xx” ;
    }
    }

    #42384
    Chris Ju
    Participant

    You are most likely right. Unfortunately, I am completely inexperienced when it comes to such things in the background.

    Maybe I am wrong. But in my opinion it would make more sense to enable the transfer of data from Tap Forms to a standard software / document such as MS Word / docx file (even without Java script as a native function and perhaps with the option of an existing Word document to update). Then one would not have to deal with the problems mentioned by Sam and the user would have the many possibilities of standard software (e.g. editing texts in MS Word).

    It would be very helpful if you could provide the video so that I can test your suggestion here.

    #42372
    Chris Ju
    Participant

    I think we’re getting off the topic a bit ;-) …

    My only problem is that long texts cannot simply be printed (or saved as PDF). If there are multiple pages I have to work with different fields and layouts.

    It would be ideal if a note field could be spanned over several pages (optionally with page numbers) as a PDF / Print.

    It is also possible – this is the subject of this thread – to include the field information (address, case number, other information, …) from Tap Forms to a Word document (via Java Script). The Word document could then simply be added to the record in Tap Forms as an attachment.

    Unfortunately, that is a very difficult topic …

    Thanks.
    Chris

Viewing 15 results - 1,636 through 1,650 (of 2,989 total)