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

    In the script editor where it has the field list, use the ID field to get the ID’s of each of the fields you want to copy across. It’ll generate a bunch of lines with fld-something that you can use with the copyField method.

    Slight refactor to Daniel’s script to create a function for copying the value across as a single line to make it easier to copy multiple fields:

    
    function copyField(fieldId, sourceRecord, destinationRecord) {
    	destinationRecord.setFieldValue(fieldId, sourceRecord.getFieldValue(fieldId));
    }
    
    function New_Lesson() {
    	let newRecord = form.addNewRecord();
    
    	copyField('fld-531d3cf087fc4b63967e29b71d30ba53', record, newRecord);
    	copyField('fld-a53801440fd543669e92f0fdf955fc85', record, newRecord);
    	copyField('fld-4f95fc5da7eb4f6d891e66f2ee620ace', record, newRecord);
    	
    	form.saveAllChanges();
    	
    	// Return id of new record
    	return newRecord.getUrl();
    
    }
    
    Utils.openUrl(New_Lesson());
    

    Attaching a sample archive as well that might help as well.

    Attachments:
    You must be logged in to view attached files.
    #42365
    Brecht DHeere
    Participant

    Thank You!
    How do I learn to create such scripts?

    #42363
    Daniel Leu
    Participant

    You could remove the unwanted data by hand or using a script.

    Thanks, Sam, for the getUrl pointer!

    Cheers, Daniel

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

    #42361
    Brecht DHeere
    Participant

    Hi Brandon, It is always the same fields that I want to keep. So removing the other data is ok. But how do I do this? With a script?

    #42338
    Daniel Leu
    Participant

    You could use ‘duplicate record’, but this would copy all fields.

    Or you can do this with a script:

    function New_Lesson() {
    	// Get current lesson
    	let lesson_id = 'fld-7131629dfa4147d79ed24f05dfc83515';
    	let lesson = record.getFieldValue(lesson_id);
    	
    	// Create new record
    	let newRecord = form.addNewRecord();
    	
    	// Copy previous record entry
    	newRecord.setFieldValue(lesson_id, lesson);
    	form.saveAllChanges();
    	
    	// Return id of new record
    	return newRecord.getId();
    }
    
    var id = New_Lesson();
    
    // Jump to new record
    Utils.openUrl("tapformz://record/view/"+document.getId()+"/"+form.getId()+"/"+id);

    Just set the lesson_id according to your form. TapForm doesn’t display the new record when it is created from a script. To do this, I use call TapForm from TapForm with the new record Id. This is done with the last statement. You can remove it if you don’t like this behavior.

    Have fun!

    Cheers, Daniel

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

    #42337
    Daniel Leu
    Participant

    If the new record is a child record, then you can use a calculation field to set the email address in the child record to the one of the parent record. This way, you won’t have to copy&paste it.

    Otherwise, you could use a script to handle this.

    Cheers, Daniel

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

    #42334
    Chris Ju
    Participant

    Thanks for your suggestion. Still does not work. Where can i find the documentation?

    I took “date_time” from https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api

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

    I figured I’d have an attempt at getting this to work and I wrote a VBA script. I got it to work to parse out a URL encoded key/value string and replace stuff and I sort of got it to work based on a template. I say sort of because if I cold load the template in Word, click “Enable Macros”, it gives me a “Object doesn’t support this action” and if I click “End”, close it out then re-open the template (and “Enable Macros” again) from Finder it seems to work properly.

    It works to the point that it takes input from the clipboard (sort of) and then replaces the document. If you look at the raw file you can see that I wrap the placeholders with two underscores and this is mapped back to the keys in the query string pattern.

    Sample text to copy:

    FirstNamePlaceholder=Tap&LastNamePlaceholder=Forms&PrizePlaceholder=one+million+dollars&TransferAmount=$200&AddressPlaceholder=1%20Infinite%20Loop%0ACupertino%2C%20CA%2095014%0AUSA&SignatureName=Steve+Jobs&
    

    To create the string to copy from an array, something like this should work (borrowed from elsewhere):

    var queryString = Object.keys(params).map((key) => {
        return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
    }).join('&');
    

    It’s janky but it is sort of functional.

    I’ve wanted a HTML type layout but printing that is oddly hard in the Apple ecosystem. There is printing support for WKWebView but apparently it’s private on the Mac and it looks like maybe it works on iOS. I found a QT based WebKit HTML to PDF library that might work on the Mac but I’m not sure if it’d pass App Store review because you’re embedding WebKit again. I found some code to create a PDF from a WKWebView using Swift that is a little newer but not sure if that’s functional. HTML layout wouldn’t replace a fully fledged multipage aware report generator that would let you do stuff like headers and footers but it might help provide some more basic use cases.

    Attachments:
    You must be logged in to view attached files.
    #42308
    Chris Ju
    Participant

    (first topic was marked as spam)

    Hi,

    i’m using the prompter dialog to enter text and date/time for a new cild record:

    let prompter = Prompter.new();
    prompter.addParameter(‘Note:’, ‘note’, ‘text’)
    .addParameter(‘DateTime:’, ‘datetime’, ‘date_time’)
    .show(‘Message prompt’, callbackFunction);

    The field “Note” is filled with the texted i entered in the dialog, but “DateTime” is still empty. What is wrong with my script?

    Is it possible to add days/weeks/years (choosing from picklist in the prompter dialog) to the current date and add the result in the DateTime field in the created record?

    Thanks
    Chris

    #42305
    Chris Ju
    Participant

    Hi,

    i’m using the prompter dialog to enter text and date/time for a new cild record:

    let prompter = Prompter.new();
    prompter.addParameter(‘Note:’, ‘note’, ‘text’)
    .addParameter(‘DateTime:’, ‘datetime’, ‘date_time’)
    .show(‘Message prompt’, callbackFunction);

    The field “Note” is filled with the texted i entered in the dialog, but “DateTime” is still empty. What is wrong with my script?

    Is it possible to add days/weeks/years (choosing from picklist in the prompter dialog) to the current date and add the result in the DateTime field in the created record?

    Thanks
    Chris

    #42302

    In reply to: Script stopped working

    Sam Moffatt
    Participant

    Ok, I finally got around writing this up, you can grab the script from my GitHub and there is also sample execution code as well. If you use my updated Script Manager you can pull down everything. The GitHub page has an example of a confirmation dialog done async and also a text input. You can use a similar approach of wrapping your method in an async block and it should execute neatly.

    Here’s a little broader of an example:

    async function comboExample() {
    	let confirmed = await promptConfirm('Are you sure?');
    	console.log(confirmed);
    
    	let details = await promptText('Enter Value', 'Location:');
    	console.log(details);
    
    	Utils.alertWithMessage("Sample messsage", "Message text");
    	console.log('Sample message');
    }
    
    comboExample();
    
    #42298
    Sam Moffatt
    Participant

    A while back I posted a Script Manager form and here I am with an updated version. This version now adds an extra form for “Repository” which adds the ability to automatically download scripts and update them. To use it, import the archive attached to this post, go to the newly created “Repository” form and use the “Update Scripts” form script to download all of the scripts listed in my GitHub repo. It provides a level of automatic versioning so that if something goes wrong you can easily rollback to a previous version of the script.

    I’ve got a video on YouTube showing how to import it and some of the features of it. I have a plan to do some more to cover some of the scripts.

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

    I don’t know how you would open a docx XML file within JavaScript, then update it and save it back. I don’t think the JavaScriptCore framework I use in Tap Forms would allow that. So Sam’s solution of copy and paste might work. Tap Forms can set values on the clipboard from a Script.

    But if you don’t need a Word file for this task, you could use Tap Forms with a custom layout and a static Text object on the layout. Within the text object, insert the field names with square brackets around the names and when you print, Tap Forms will substitute the values.

    For example:

    Dear [First Name] [Last Name],
    
       We have come to the realization that you need to pay $[Amount Due] by [Due Date] or you will be charged an additional [Penalty Percent]% interest on your loan.
    
    Sincerely,
    
    The Lending Company

    You can even stylize the text within the Text object.

    To add a Text object, click the Layout button, then click the A button above the layout inspector panel. Then click on your layout and type in your form. You can even paste from Word into there. But I would probably paste as plain text to remove any formatting and then use Tap Forms to format. Word might add all kinds of crap into the formatting that you don’t want.

    If you need more than one page though, you can add another layout and then chain the layouts together.

    Thanks!

    Brendan

    #42296
    Chris Ju
    Participant

    My idea was to replace text/field (e.g. “nName”, “aAddress”, …) in the docx (=xml) file with the content from Tap Forms fields (name, address, …) using javascript. I know, that it is possible with apple script in other apps…

    #42295
    Sam Moffatt
    Participant

    I thought I’d replied to this but I guess I didn’t hit submit or something.

    My immediate thought would be to use the clipboard to shuttle data around, encode it in Tap Forms and then use VBA to grab the clipboard and splice it into the template, if you put the file in the script directory for Tap Forms then you might be able to attach it via a script as well though it’s a little janky all told.

    Some other folk have had success with AppleScript and also Keyboard Maestro that might be able to automate things.

    I’m not sure any of it is a good solution for automating Word but that might help you along.

Viewing 15 results - 1,651 through 1,665 (of 2,989 total)