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,951 through 1,965 (of 2,952 total)
  • Author
    Search Results
  • #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.

    #40190
    Chris Ju
    Participant

    If you’re actually going to offer subscriptions, count me in as a first customer. I’d be more than willing to pay for it, especially since I’ve been using your software for years and only paid $50+- !

    You can count on me promoting this stuff in the large computer repair communities if you ever decide to take the jump (or rather, climb Mt. Everest:-) )

    You can count on me right away! … ;-)

    #40171
    Sam Moffatt
    Participant

    I don’t think the Javascript API currently has the depth in the request methods to make this happen. If you can specify the authentication credentials as a part of the POST request body or as a part of the query string then it should work. If you need to use basic auth, a custom header or some sort of cookie based auth, I don’t think the current API readily supports that.

    You might need to build your own bridge to handle the authentication into WordPress and then use either a query string or as a part of a POST body.

    #40159
    Tom Dropes
    Participant

    Hi all,

    I have a WP site were I would like to grep some informations via api to Tapforms. I have a json path which is already connected and working with Zapier.

    I’m trying to find a Javascript code WITH basic API Key authorization included. With the code in the script editor in TapForms I got an authorization error. Who can help me to include the authorization code in the script:

    function fetchFromURL() {
    var xxxxx = Utils.getJsonFromUrl(‘https://myjsonpath&#8217;);
    return xxxxx[0];
    }

    fetchFromURL();

    Thank you in advance!!!

    Tom

    This is the error:

    {
    code = “rest_forbidden_context”;
    data = {
    status = 403;
    };
    message = “Sorry, you are not allowed to view entries”;
    }

    #40111
    Hans
    Participant

    Thanks a lot for thinking with me!

    This is the result of the script, hope I did the execution right (see attachment).

    30-03-20 09:52:59 / Trades / Tijdberekening
    “1970-01-01T14:51:02.000Z”
    Thu Jan 01 1970 15:51:02 GMT+0100 (CET)
    undefined
    undefined

    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 1,951 through 1,965 (of 2,952 total)