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 - 616 through 630 (of 2,989 total)
  • Author
    Search Results
  • #49092

    In reply to: Simple previous

    Brendan
    Keymaster

    The Number Formatter setting you use on your Number fields will make no difference to your script. Tap Forms just sees those values as raw numbers without formatting anyway when being processed in a script.

    You are missing a semi-colon at the end of your console.log statement though. Not that that would cause the NaN error.

    Does your $/grp field return a valid number from its calculation? Is its formula set to return a Number result type?

    #49084

    In reply to: Simple previous

    Daniel Leu
    Participant

    1) There is a missing closing curly bracket after return 0;.

    2) This script is a field script and not a form script.

    • This reply was modified 2 years, 10 months ago by Daniel Leu.
    • This reply was modified 2 years, 10 months ago by Daniel Leu.

    Cheers, Daniel

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

    #49082
    Glen Forister
    Participant

    I’ve applied your “previous_field” script to several Forms and been quite successful, but this is about as simple as you can get and I can’t figure out what I’ve missed. See attached.

    Also, does it matter where the script is used: 1) the script in the field window or 2) the script in the Script tab? Is there any difference between the two in the code?

    Attachments:
    You must be logged in to view attached files.
    #49062
    Bucky Edgett
    Participant

    New user here; replacing old FileMakerPro with Tap Forms. I’m accustomed to “formatting” text within fields, especially for Notes and descriptions and such. That is, bolding words, adding line breaks, etc. I cannot perform any actions within a Text “Notes” field other than typing new text.

    This might be a problem with my computer: a 2014 mac mini running High Sierra 10.13.6.; Legacy 32 bit software I can’t yet afford to replace; inexpensive keyboard; who knows?

    Any advice would be appreciated!

    Yours,
    Bucky

    #49056

    Topic: Blank value

    Glen Forister
    Participant

    I can’t find a way (probably not possible) to return a value of “BLANK” instead of a zero.
    Is there a way in this equation?
    (IFNOTEMPTY(Purchased;MONTHS(Purchased;TODAY());0))/12
    Thanks.
    Maybe, use the results of this field, call it into another field and and Script it there with an if statement if it is zero, leave it blank?
    All those zeros are distracting from seeing my data.

    Thanks.

    #49052
    Sam Moffatt
    Participant

    I wanted to do a demo of some of the functionality and two sample scripts with a sample form. The form is a shipping tracker with a tracking number, ship date, delivery date, confirmed date and notes field. There are some pre-canned managed field configurations set and two scripts. I’ve attached a Tap Forms 5 archive you can use to check out the structure.

    The first script, Confirm Received, uses a prompter to ask for a tracking number and if the record exists updates it to set the confirmed date to be the current date. This uses setIfEmpty on the confirmed date field to only update the field if it doesn’t have a value already. This allows you to “confirm” a package multiple times but only the first time will be stored. It looks like this:

    const PARENT_SCRIPT = form.name + "::" + scriptName;
    
    document.getFormNamed("Script Manager").runScriptNamed("Managed Fields");
    document.getFormNamed("Script Manager").runScriptNamed("getRecordFromFormWithKey");
    
    var tracking_number_id = 'fld-91af3b8b61d041db888921726f333a3b';
    var ship_date_id = 'fld-d38551668df3406589c8594921be0c86';
    var delivery_date_id = 'fld-c0a0d5647dc34126b6c82baabab69cf7';
    var confirmed_date_id = 'fld-fc04420bee174714940951aada52254d';
    var notes_id = 'fld-8effa85f9bc147538211a16cfd961de9';
    
    var callbackFunction = function(continued) {
    	if (!continued) {
    		return;
    	}
    	
    	if (!tracking_number) {
    		Utils.alertWithMessage("Missing tracking number", "Tracking number is required!");
    		return;
    	}
    	
    	console.log(tracking_number);
    	
    	let targetRecord = getRecordFromFormWithKey("Shipments", tracking_number_id, tracking_number, false);
    	if (!targetRecord) {
    		Utils.alertWithMessage("Unknown tracking number", "Item not found");
    		return;
    	}
    	
    	targetRecord.setManagedFieldValue(confirmed_date_id, new Date());
    	document.saveAllChanges();
    };
    
    var tracking_number;
    let prompter = Prompter.new();
    prompter.addParameter('Tracking Number', 'tracking_number', 'text')
    	.show('Confirm Package Received', callbackFunction);
    

    The second script, Handle Shipment Update, is a little longer and leverages some more prompter functionality to handle if a shipment is “shipped” or marked “delivered”. This workflow is useful for when someone sends a notification that the package shipped or there is a carrier delivery notification. It has some more prompter examples and demonstrated setManagedFieldValue to ensure that the field is updated properly:

    const PARENT_SCRIPT = form.name + "::" + scriptName;
    
    document.getFormNamed("Script Manager").runScriptNamed("Managed Fields");
    document.getFormNamed("Script Manager").runScriptNamed("getRecordFromFormWithKey");
    
    var tracking_number_id = 'fld-91af3b8b61d041db888921726f333a3b';
    var ship_date_id = 'fld-d38551668df3406589c8594921be0c86';
    var delivery_date_id = 'fld-c0a0d5647dc34126b6c82baabab69cf7';
    var confirmed_date_id = 'fld-fc04420bee174714940951aada52254d';
    var notes_id = 'fld-8effa85f9bc147538211a16cfd961de9';
    
    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');
    			}
    		}));
    	});
    }
    
    var callbackFunction = async function(continued) {
    	if (!continued) {
    		return;
    	}
    	
    	if (!tracking_number) {
    		Utils.alertWithMessage("Missing tracking number", "Tracking number is required!");
    		return;
    	}
    	
    	if (!event_type) {
    		Utils.alertWithMessage("Missing event type", "Please specify the event type to continue.");
    		return;
    	}
    	
    	let targetDate = new Date();
    	if (event_date) {
    		targetDate = new Date(event_date);
    	}
    	
    	console.log(tracking_number);
    	console.log(event_type);
    	console.log(event_date);
    	console.log(targetDate);
    	
    	let targetRecord = getRecordFromFormWithKey("Shipments", tracking_number_id, tracking_number, false);
    	if (!targetRecord) {
    		try {
    			await confirmExecution('Create new record?');
    		} catch (errorText) {
    			// user clicked 'No'
    			console.log('cancelled');
    			return;
    		}
    	
    		// user clicked 'yes'
    		// continue with function
    		console.log('continue from yes');
    		targetRecord = form.addNewRecord();
    		targetRecord.setManagedFieldValue(tracking_number_id, tracking_number);
    	}
    
    	switch (event_type) {
    		case "Shipped":
    			targetRecord.setManagedFieldValue(ship_date_id, targetDate);
    			break;
    		case "Delivered":
    			targetRecord.setManagedFieldValue(delivery_date_id, targetDate);
    			break;
    	}
    	
    	document.saveAllChanges();
    };
    
    var createNewRecord;
    var tracking_number;
    var event_type;
    var event_date;
    let prompter = Prompter.new();
    prompter.addParameter('Tracking Number', 'tracking_number', 'text')
    	.addParameter('Event Type', 'event_type', 'popup', ['Shipped', 'Delivered'])
    	.addParameter('Event Date', 'event_date', 'text')
    	.show('Handle Shipment Update', callbackFunction);
    
    • This reply was modified 2 years, 11 months ago by Sam Moffatt.
    Attachments:
    You must be logged in to view attached files.
    #49046
    Jon Millar
    Participant

    Thanks Brendan that’s great.

    To fine tune it though, I need to get the record field details into the Message body, I imagine something like creating variables with “getFieldValue” and then putting those variables into the Email body. Is that Straight forward?

    One more thing. That script beautifully creates the email but can the script also automatically send it rather than just create it and leave it for you to manually “send” ?

    Thanks again
    Cheers
    Jon

    #49045

    In reply to: Copy Record to Form

    Brendan
    Keymaster

    Whenever you use the record.getFieldValue(field_id); command in a Field Script, Tap Forms will run that script whenever the value in that referenced field changes.

    So you can have it triggered when you change some value in a form. That script can add a record to another form and copy the values from that record to the record in the other form.

    I would recommend referencing the last field in your form thought to trigger running of the script. That way you can fill in all the fields in the record first, then when you get to the last field and enter in a value, your script will run and will copy all of the values entered in that record to the record in the other form.

    #49043
    Glen Forister
    Participant

    I ran across a Script function defined to copy a record from form to another.
    function Copy_Record_To_Form()

    See attached. I have two forms, each with hundreds of records which I add to frequently. The problem is they were made at different times for different reasons and both contain much of the same information. Is it possible to fill out a new record in one of the records and somehow copy the information that is common to both to the other Form? Going in one direction from one to the other, depending on which form gets filled out first and then need to fill out a record in the other form?

    Attachments:
    You must be logged in to view attached files.
    #49037
    Brendan
    Keymaster

    Hi Jon,

    You could try the Utils.openUrl() method.

    This would work to create the email. It’ll launch your mail program and put in the subject and body.

    function Email_User() {
    
        let subject = encodeURIComponent("Testing 123");
        let body = encodeURIComponent("This is what I want to say in the email");
        Utils.openUrl("mailto:support@tapforms.com?subject=" + subject + "&body=" + body);
    
    }
    
    Email_User();

    You would have to put the script into a Script Field on your Table field though. Then you’ll have to reference your Date field in your script, which will cause the trigger and add a check to see if the date is today before running the above code.

    #49034

    In reply to: If loop

    Glen Forister
    Participant

    It works, but as I feared, I notice these equations return integers, not actual decimal numbers indicating parts of an integer. I guess I have to do this in Script to get a real value???

    I was able to get YEARS AND MONTHS, but not a real value, just an approximated value. Number Format is decimal with 2 places.

    See pic attached.

    • This reply was modified 2 years, 11 months ago by Glen Forister.
    • This reply was modified 2 years, 11 months ago by Glen Forister.
    Attachments:
    You must be logged in to view attached files.
    #49028
    Jon Millar
    Participant

    Hi All. Loving TapForms so far,

    Is there any way to create a script that will run automatically when a record date field from a table = todays date?

    Any help gratefully revived
    Cheers
    Jon

    • This topic was modified 2 years, 11 months ago by Jon Millar.
    #49020

    In reply to: Learning JavaScript

    footlooseboss
    Participant

    for future readers as much as OP:

    Can someone recommend any books, videos, etc. to learn JavaScript, particularly in relation to Tap Forms 5 rather than web use?

    I used Khan Academy to teach myself further maths; they have a course on JavaScript. I found it better than a real tutor (pause + rewind). Probably start with a few modules here.

    I learnt two ways:
    – downloading the source of a website, modifying it, breaking it, fixing it
    – setting a goal of writing a script to do something useful on a webpage automatically – in my case it was logging into a booking website every day, finding available time slots, and booking the first slot before anyone else

    I can suggest tools but to start experimenting just enable the developer menu in Safari, and open inspector/console.

    Tap Forms API reference:
    tapforms.com/help-mac/5.3/en/topic/javascript-api

    Tap Forms scripting videos (fairly in-depth, probably don’t start here)
    pasamio YouTube

    edit: format

    • This reply was modified 2 years, 11 months ago by footlooseboss.
    #48992

    In reply to: Prompter issue

    Sam Moffatt
    Participant

    I think the snippet is ok, it’s just if you run the snippet inside of a function it’ll insert it there. I think an improvement for a future prompter would be a way of having the callback accept the return values as a dictionary which would remove the need to have the variables defined at the right scope (which for Javascript is a challenge at times).

    #48988

    In reply to: days between dates

    Brendan
    Keymaster

    There are all sorts of functions you can perform on JavaScript Date objects without having to do the math yourself:

    https://www.w3schools.com/js/js_date_methods.asp

Viewing 15 results - 616 through 630 (of 2,989 total)