Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 5, 2020 at 7:13 PM #42504
In reply to: Simple Prompter Message
Sam Moffatt
Participant+1 to sometimes the GUI and the script engine have different views of the actual underlying state (generally the script is correct and GUI is out of sync).
November 5, 2020 at 10:49 AM #42501In reply to: Simple Prompter Message
Daniel Leu
ParticipantThe first version of the code was missing the
form.saveAllChanges();. The second version of your code will delete all records that have the same naam. This might not be what you want.I would update the first version with
form.saveAllChanges();. Sometimes the TapForms GUI doesn’t refresh upon changes. So the record might be deleted but you just don’t see it. Try clicking on ‘recalculate formulas’ to get the display updated. This should be fixed in the future (https://www.tapforms.com/forums/topic/advice-on-script-triggering/#post-42484).Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 5, 2020 at 1:00 AM #42496In reply to: Simple Prompter Message
Brecht DHeere
ParticipantThanks Daniel!
I tried to set the scriptline for deleting the record in this place (see below) but the record is still there after I run the script until I refresh. Is this normal or am I doing something wrong?
Thanks,
Brecht…
async function myFunction() {try {
await confirmExecution(‘Do you really want to delete the record?’);
} catch (errorText) {
// user clicked ‘No’
console.log(‘cancelled’);
return;
}// user clicked ‘yes’
// continue with function
// main code here
form.deleteRecord(record);
console.log(‘continue from yes’);}
myFunction();
Attachments:
You must be logged in to view attached files.November 4, 2020 at 9:33 AM #42491In reply to: Simple Prompter Message
Daniel Leu
ParticipantIn the script editor, there is the
Prompt for confirmationtemplate. That’s a good starting point. For your example, I just changed one string:function confirmExecution(question) { return new Promise(function(resolve, reject) { let prompter = Prompter.new(); prompter.cancelButtonTitle = 'No'; prompter.continueButtonTitle = 'Yes'; prompter.show(question, ((status) => { if (status == true) { resolve('Yes'); } else { reject(question + 'No'); } })); }); } async function myFunction() { try { await confirmExecution('Do you really want to delete the record?'); } catch (errorText) { // user clicked 'No' console.log('cancelled'); return; } // user clicked 'yes' // continue with function // main code here console.log('continue from yes'); } myFunction();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 2, 2020 at 2:26 PM #42484In reply to: Advice on script triggering
Brecht DHeere
ParticipantHi,
Why do I need to refresh before the record is deleted?
I’m using a field script on the Mac version.Thanks,
Brechtvar checkmark = record.getFieldValue (‘fld-cf7c770a0bb04dc7922e79b24467bbd1’);
if (checkmark) {
form.deleteRecord(record)
}
form.saveAllChanges();October 30, 2020 at 12:44 AM #42446In reply to: Basic information on scripting.
Sam Moffatt
ParticipantI had an attempt at making a much in depth look at the script field and also the first snippet which is the if statement. I’m not sure if it hits the mark or not but I figured I’d start by working through each of the snippets but then after I’d done a few test attempts decided to spend a lot more time on script fields in general and some of their quirks.
October 27, 2020 at 6:57 PM #42436In 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 :)
-
AuthorSearch Results