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,621 through 1,635 (of 2,989 total)
  • Author
    Search Results
  • #42524

    In reply to: Missing Field

    Daniel Leu
    Participant

    Patrice, just quoting Brendan from an earlier post:

    Hi Patrice,

    If you email me a backup of your document I can probably restore it.

    or check the “Restore deleted items…” function in the File menu to see if it appears there.

    Sorry for this trouble.

    Thanks,

    Brendan

    Brendan can be reached at support@tapforms.com.

    I have never encountered lost data as you describe it. Do you use any formulas or scripts that might have an unwanted side effect?

    Cheers, Daniel

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

    #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());
    
Viewing 15 results - 1,621 through 1,635 (of 2,989 total)