Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
October 26, 2020 at 10:49 PM #42426
In reply to: Students –Courses
Sam Moffatt
Participant1. If you’re mapping multiple records together it’s the approach I recommend. You might end up wanting a fourth one to map courses to instances of the course that a student is enrolled in (sessions/semesters/offerings/something) but that might be going a bit too far.
2. You could put a script field inside your link form that joins all of the students into the link form or the course form. If you did an enrolments script field on the course that joined the students enrolled in it and set it as one of the list fields then it’ll show up when you’re selecting courses.
3. If you’re after a table of course to student list then the above script field should help there as well.
October 26, 2020 at 8:54 PM #42425In reply to: Copy data from field to new record
Sam Moffatt
ParticipantOf course! So this one is a little more indirect, you need to change the
let newRecord = form.addNewRecord();line to look at the parent of the current record.First step is to go to our Students form and double click on “Lessons” in the field list of script editor to copy the field ID of the “Lessons” link field, in the database I had, it generates this line
var lessons_id = 'fld-bd0476420e504001a5f20833fc66e7cb';.Now we jump back to our Lessons form and nuke the
let newRecordline, paste in thelessons_idline from above and double click on the “Students” in the field list of the script editor to get thestudents_idfield:var lessons_id = 'fld-bd0476420e504001a5f20833fc66e7cb'; var students_id = 'fld-a9af1b4e918b4cf2b9f7737de6476e40';Our next step is to get the parent Student record and then use it to add a new Lesson record to it:
var student = record.getFieldValue(students_id); var newRecord = student.addNewRecordToField(lessons_id);Putting it all together the updated script looks like this:
function copyField(fieldId, sourceRecord, destinationRecord) { destinationRecord.setFieldValue(fieldId, sourceRecord.getFieldValue(fieldId)); } function New_Lesson() { var lessons_id = 'fld-bd0476420e504001a5f20833fc66e7cb'; var students_id = 'fld-a9af1b4e918b4cf2b9f7737de6476e40'; var student = record.getFieldValue(students_id); var newRecord = student.addNewRecordToField(lessons_id); 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());October 26, 2020 at 1:32 AM #42420In reply to: Basic information on scripting.
Sam Moffatt
ParticipantPart 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 :)
October 26, 2020 at 1:02 AM #42415Sam Moffatt
ParticipantYes, 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 FunctionThat should fix that other error up as well.
October 26, 2020 at 12:23 AM #42412In reply to: Total value in a Calculation Field?
Brendan
KeymasterHi 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_idfor your form’s Number field of course.Set the Return Type of the Script to be Number.
October 25, 2020 at 10:37 PM #42408Chris Ju
ParticipantI tested the files, but i get an error (see screenshot).
Are you sure i have to put
TFIntegration.scrptinto~/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.October 25, 2020 at 3:33 PM #42404Sam Moffatt
ParticipantOk, 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.Wordso 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 decodeURIComponentBasically 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 FunctionAgain this is expecting a file named
TFIntegration.scrptto be in~/Library/Application Scripts/com.microsoft.Wordto 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.October 25, 2020 at 9:34 AM #42402In reply to: Empty Date gives 1970
Sam Moffatt
ParticipantThe 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.
October 24, 2020 at 12:11 PM #42391In reply to: My first script … no effect
Sam Moffatt
ParticipantSo
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,Demisn’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
phoneDemfield 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
demwhich 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 withdocument.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.October 24, 2020 at 12:02 PM #42390In reply to: Script to delete record
Sam Moffatt
ParticipantThe currently selected record is generally
record, so to delete it you just need to doform.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.
October 24, 2020 at 10:49 AM #42389Sam Moffatt
ParticipantOk, 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.
October 24, 2020 at 6:14 AM #42388In reply to: Basic information on scripting.
T.L. Ford
ParticipantOctober 24, 2020 at 2:45 AM #42387In reply to: Script to delete record
Brecht DHeere
ParticipantHi, 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?
October 24, 2020 at 2:10 AM #42386Topic: Basic information on scripting.
in forum Script TalkMichael Mckenna
ParticipantHi, 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.
October 24, 2020 at 12:13 AM #42385Topic: My first script … no effect
in forum Script TalkChristian Rommens
ParticipantI 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” ;
}
} -
AuthorSearch Results