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 - 2,101 through 2,115 (of 3,106 total)
  • Author
    Search Results
  • #40268

    In reply to: User calculation

    Brendan
    Keymaster

    Yes, you could certainly do that with a Form Script.

    You would use the functions: record.getFieldValue(field_id) to get the value from your Total field, then perform your calculation on that value, then call record.setFieldValue(vat_id) to set the value on your VAT field.

    Then call form.saveAllChanges(); to save the results.

    #40264

    In reply to: User calculation

    Yes, I could indeed use the calculation field, but in most cases I don’t need this calculation.
    I now have an invoice with the input of services that are added together and then calculated with VAT to the total. Only in very rare cases do I have to calculate the other way round, so I have the total and have to calculate the amount without VAT.
    Is this then possible to do it with the help of a script?

    Tanks!

    Attachments:
    You must be logged in to view attached files.
    #40258
    Sam Moffatt
    Participant

    I have a script I use that I think I’ve posted elsewhere for the ordering of child records, that means you can edit the ordering field relatively straightforward. It’s a reply to a similar sort of thread. I’ll reply here if I find it again.

    #40252
    Victor Warner
    Participant

    Thank you, but a brief look at the link does not provide how, what and where I add the relevant regular expression. The code provided in the linked page does not seem to relate at all (for someone who does not know JavaScript) to the examples you have provided.

    Can you, Brendan, or someone else provide how it is possible to search for any text appearing in a field (as a wildcard, whether with regular expression or without) and replace it with something?

    #40251
    Ron Kline
    Participant

    I have a prompter that allows a user to key in several pieces of information about a contact such as First Name, Last Name, Street Address, City, State, Zipcode, Phone Number, Email, Emergency Contact First Name, Emergency Contact Last Name, Emergency Contact Phone Number, etc. Due to the number of .addParameter entries the prompter window gets a little cluttered. To try and make it look a little more organized I would like to add some space in the prompter window between the Contact collection fields and the collection fields for their Emergency Contact. Is there a way to do this by adding a line with just plain text to show where the Emergency Contact entry fields start?

    #40250

    Topic: User calculation

    in forum Script Talk

    Hi,

    I need a script which makes a simple calculation on user input.
    The user inputs: amount inclusive tax and: a tax rate (from a list); the script then calculates the amount excl tax and puts it in the appropriate field.

    e.g. user input 150,00 and 21%
    output from script: 123,97

    I tried it with the Prompter class example from the documentation but without succes…
    I am not a programmer..

    Thanks in advance!

    Andreas.

    #40248
    Brendan
    Keymaster

    You would definitely need a Script field for this.

    So you would want to return the first or last sub-record within the table field, depending on how you’re sorting it. Then you would set your parent form to sort by the Script field.

    Here’s a sample script:

    function getTableDateValue() {
    
    	var table_id = 'fld-c433974d87de4bbca4eae626bc412408';
    	var date_time_id = 'fld-56d1a49577574de1a229e66f1acaf676';
    	var table_records = record.getFieldValue(table_id);
    	var date_time;
    	
    	if (table_records.length > 0) {
    		var first_record = table_records[0];
    		var last_record = table_records[table_records.length - 1];
    		date_time = first_record.getFieldValue(date_time_id);
    	}
    	return date_time;
    }
    
    getTableDateValue();

    Either you return the first_record’s date_time value or the last_record’s date_time value depending on how your Table field records are sorted and if you want to get the minimum or maximum date value.

    Hope that gets you started. You’ll need to use your own field IDs of course.

    Brendan

    #40244
    Wolfgang
    Participant

    Is there a way to sort records by a table-field date? And if I have more than one event in the table, sorting the records by the newest date? The table itself is sorted in ascending order (the newest is last).
    I can imagine that’s a good job for a script! I can read and adapt scripts, but not so well at all in writing them ?. But maybe there is a standard way…

    #40243
    Daniel Leu
    Participant

    For the second problem, in conventional find and replace, the find part would done through a wildcard

    You can use regex: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

    Cheers, Daniel

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

    #40242
    Victor Warner
    Participant

    Okay, but neither work were

    1. the 3 Test fields contain, respectively, 1, 2, and 3; and
    2 I wish to replace with them with 0.

    The second does, as you write, does add a 0 where the field is empty. That is one problem I am trying to solve. The other is to replace any text appearing in the field with a 0 (as a I mentioned already, the first script, simply adds the replacement 0 to the existing text and not replaces it). For the second problem, in conventional find and replace, the find part would done through a wildcard

    My problem is that I do not know JavaScript so I do not know how to fix it to do it what I want.

    #40241
    Daniel Leu
    Participant

    Thank you for sharing your script, Victor.

    The first script is NOT to be used with empty text. You need to use the second script for that. I deleted one test field and run the second script which properly updates the empty field with 0.

    I created two scripts so others can profit as well. I don’t consider search for “” and replace with “something” to be a normal use case. That’s why I added the second script. For your use case, you only use the second script! It does a regular search and replace, and for cases where the field is empty, it puts the replacement text in there.

    Cheers, Daniel

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

    #40239
    Victor Warner
    Participant

    Thank you for the further explanation. But I am clearly missing something.

    In the attached sample Form I have a field “Test” with 3 records, containing 1, 2, 3.

    I would like to replace all the entries with 0, but neither set of code works (creating Form Scripts you provided). The first one (“F&R – anything from something”) adds a 0 to 1, 2, 3 (01, 02, 03) while the second one (“F&R – nothing with something) does nothing at all.

    Am I doing something wrong? Any further help would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    #40233
    Daniel Leu
    Participant

    Everything is possible with a script, well almost ;-)

    Here is the version that doesn the replacement of strings in a field:

    var field_id = 'fld-64b0b17a635f49b8b40867e45f8d24db';
    
    function findAndReplace(find_text, replace_with) {
    	for (let rec of form.getRecords()){
    		let value = rec.getFieldValue(field_id);
    		if (value) {	
    			rec.setFieldValue(field_id, value.replace(find_text, replace_with));
    		}
    	}
    	form.saveAllChanges();
    	return;
    }
    
    findAndReplace("Ford", 'Tesla');

    And this version replaces an empty field with the replacement text:

    var field_id = 'fld-34fb289f2b124f26982df66430b31fbd';
    
    function findAndReplace(find_text, replace_with) {
    	for (let rec of form.getRecords()){
    		let value = rec.getFieldValue(field_id);
    		if (find_text === ""){	// special case with empty string
    			if (value == undefined){
    				rec.setFieldValue(field_id, replace_with);
    			}
    		} else {
    			if (value){
    				rec.setFieldValue(field_id, value.replace(find_text, replace_with));
    			}
    		}
    	}
    	form.saveAllChanges();
    	return;
    }
    
    findAndReplace("Ford", 'Tesla');

    Enjoy!

    Cheers, Daniel

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

    #40227
    Victor Warner
    Participant

    I found the find and replace script posted by Brendan at https://www.tapforms.com/forums/topic/find-and-replace-script/ very helpful, but would like some help in adapting it:

    var field_id = 'fld-64b0b17a635f49b8b40867e45f8d24db';
    
    function findAndReplace(find_text, replace_with) {
    	
    	var records = form.getRecords();
    	
    	for (var index = 0, count = records.length; index < count; index++){
    		var rec = records[index];
    		var value = rec.getFieldValue(field_id);
    		if (value == find_text) {
    			value = replace_with;
    			rec.setFieldValue(field_id, value);
    		}
    	}
    
    	document.saveAllChanges();
    	
    	return;
    }
    
    findAndReplace('Ford', 'Tesla');

    specifically:

    1. at present it searches for a specific item in a specific field. How is it possible to search for anything in that field and replace with specific text (so rather than ‘Ford’ in Brendan’s example, there might be Ford, Mercedes or BMW etc). I have tried adding a wildcard indicator (*), but it does not work.

    2. A variation on 1. is where there is nothing in the specific field. Changing ‘Ford’ in Brendan’s example, to ” also does not work.

    Is this possible with the script?

    Any help would be gratefully received.

    #40194
    Brendan
    Keymaster

    Hi Chris,

    Thanks for the feature request.

    You can probably do this now with the new Calendar and Reminders API I added to the Scripting engine. You can add an event to a calendar from a Script and store the event and reminder’s identifier in a field somewhere in Tap Forms and then at a later date, recall that identifier and modify the event or reminder.

    See the updated docs for more details:

    https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api

    The new functions are at the bottom of the page.

    So you could have a script that monitors a date field in Tap Forms and adds or updates an event or reminder when that date field changes.

Viewing 15 results - 2,101 through 2,115 (of 3,106 total)