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,786 through 1,800 (of 3,153 total)
  • Author
    Search Results
  • #42504
    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).

    #42501
    Daniel Leu
    Participant

    The 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&tricks

    #42496
    Brecht DHeere
    Participant

    Thanks 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.
    #42491
    Daniel Leu
    Participant

    In the script editor, there is the Prompt for confirmation template. 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&tricks

    #42484
    Brecht DHeere
    Participant

    Hi,

    Why do I need to refresh before the record is deleted?
    I’m using a field script on the Mac version.

    Thanks,
    Brecht

    var checkmark = record.getFieldValue (‘fld-cf7c770a0bb04dc7922e79b24467bbd1’);
    if (checkmark) {
    form.deleteRecord(record)
    }
    form.saveAllChanges();

    #42446
    Sam Moffatt
    Participant

    I 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.

    #42436

    In reply to: Students –Courses

    Sam Moffatt
    Participant

    Implementing 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).

    #42435
    Brecht DHeere
    Participant

    New Feature
    OK, it will come…

    #42432

    In reply to: Students –Courses

    Brecht DHeere
    Participant

    OK, 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?

    #42431
    Brecht DHeere
    Participant

    Yes, 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?

    #42430
    Sam Moffatt
    Participant

    Every 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.

    #42429
    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 :)

    #42426

    In reply to: Students –Courses

    Sam Moffatt
    Participant

    1. 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.

    #42425
    Sam Moffatt
    Participant

    Of 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 newRecord line, paste in the lessons_id line from above and double click on the “Students” in the field list of the script editor to get the students_id field:

    	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());
    
    #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 :)

Viewing 15 results - 1,786 through 1,800 (of 3,153 total)