Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
October 27, 2020 at 6:57 PM #42436
In reply to: Students –Courses
Sam Moffatt
ParticipantImplementing that one is relatively straight forward, the child records loop does most of the heavy lifting for you. I need to go and time code the video but the intro to scripting video covers this (though perhaps I need to go take “simple” out of the title).
October 27, 2020 at 4:44 PM #42435In reply to: Copy data from field to new record
Brecht DHeere
ParticipantNew Feature
OK, it will come…October 27, 2020 at 9:22 AM #42432In reply to: Students –Courses
Brecht DHeere
ParticipantOK, number 2 seems a good solution but I can’t write such scripts :(
You don’t have a sample script that I can change for my form?October 27, 2020 at 8:14 AM #42431In reply to: Copy data from field to new record
Brecht DHeere
ParticipantYes, when I refresh the data is ok. Sometimes I have to go to field view to refresh.
It is not possible with a script to refresh that record? And is that a bug in TF?October 27, 2020 at 7:47 AM #42430In reply to: Copy data from field to new record
Sam Moffatt
ParticipantEvery so often TF doesn’t refresh the calc/script fields after a script execution, at the bottom of the record is a refresh to recalc that record and at the bottom of the list view is another one that will apply to all records in the form. If you see a calc/script field that looks wrong, just hit the refresh button and see if it fixes it up.
October 27, 2020 at 4:32 AM #42429In reply to: Email field autofill emailaddress
Brecht DHeere
Participant@Brendan: I figured it out already. New line in mailto: = %0A
The button thing is not working because I don’t know if it is possible to send email with a script. But I’m using the globe of the Website Address field in my new layout as a button and that works fine :)
October 26, 2020 at 10:49 PM #42426In 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. -
AuthorSearch Results