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 - 571 through 585 (of 2,951 total)
  • Author
    Search Results
  • #49120
    Brendan
    Keymaster

    Does WooCommerce have a REST API? Maybe as you edit your data in Tap Forms, a script can use the Utils. postContentToUrlWithContentType() or Utils.postJsonToUrl() functions.

    To avoid the refreshing issue, maybe instead of using a Field Script, use a Form Script and have it loop through your records, updating the exportable fields with the values from the regular fields. So when you’re going to export, just run the script first. Then it won’t be interrupting you while you edit the records.

    #49119
    Daniel Leu
    Participant

    To duplicate a field value I would use a calculation field. You just have to pay attention to use the correct return type.

    Another option I could imagine is creating the CSV from a form script. Once done, copy it to the clipboard with Utils.copyTextToClipboard(). I don’t know if you directly can use the copied text in WooCommerce. If you need a file, then maybe use an AppleScript that calls your TF script to get the data and then saves them to a file. But that’s getting a bit more complicated.

    Cheers, Daniel

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

    #49118
    Kirk Williams
    Participant

    Greetings!

    I have a form that contains a database of products that are exported to a WooCommerce site. Each item has a number of “attribute” fields that are included when exporting the record data.

    The problem I was attempting to solve with the script below is that WooCommerce requires specific titles for CSV columns. I initially named my fields to correspond with the export requirements but quickly found that having to remember that “Attribute 5” equals “Model”, etc. was too cumbersome.

    My first crack at a workaround was to rename my fields with logical identifiers, then use MS Excel to rename the exported columns to the terms required by WooCommerce. This worked but still felt like an unnecessary extra task.

    I then concocted this script that essentially involves duplicate fields within TapForms itself. One column is named logically (ex: “Model”), while the duplicate is named to accommodate the WooCommerce import requirements (ex: “Attribute 5”). Obviously, the data in both fields need to be identical, so I’m using this script to automatically update certain fields whenever its corresponding field is modified:

    function wc_attributes_update() {

    var year_id = 'fld-bcf37649c9ee4332b7100a9589110f96';
    var year = record.getFieldValue(year_id);
    var manufacturer_id = 'fld-17e5cb32753f43eea332701c2587d2d6';
    var manufacturer = record.getFieldValue(manufacturer_id);
    var model_id = 'fld-81bfab5a547e4c59a46fb5c3fb795fbc';
    var model = record.getFieldValue(model_id);
    var gauge_id = 'fld-28d551114d734843a0e64680575e991e';
    var gauge = record.getFieldValue(gauge_id);
    var container_id = 'fld-b0c7a9bbb57a40a891c659346fa63ae0';
    var container = record.getFieldValue(container_id);
    var era_id = 'fld-0101387087f044ddb402ae2111b2a854';
    var era = record.getFieldValue(era_id);
    var railroad_id = 'fld-c522d3a2b0e245e69f21f8eb3553be83';
    var railroad = record.getFieldValue(railroad_id);
    var brand_id = 'fld-f2dcf5e1818a4e588863424cc70e9804';
    var brand = record.getFieldValue(brand_id);
    var collection_id = 'fld-b133cb39179f4083b5377f7f01ecb1ea';
    var collection = record.getFieldValue(collection_id);
    var tca_grade_id = 'fld-0699ee653f564342855aa82798c88a01';
    var tca_grade = record.getFieldValue(tca_grade_id);
    var attribute_1_value_s_id = 'fld-722b1a029a2e4e8bbadd9cbf481d060f';
    var attribute_2_value_s_id = 'fld-828e1965c3ce4fa88b6a12b2dba89d39';
    var attribute_3_value_s_id = 'fld-a3e517222cd143e79323d7e99641c00c';
    var attribute_4_value_s_id = 'fld-8480a45102ed499cb00008b4c38625c7';
    var attribute_5_value_s_id = 'fld-9c0b1069d7024d46a519749589fef59e';
    var attribute_6_value_s_id = 'fld-f95371e7ac824cba92cf80da77c2fd7a';
    var attribute_7_value_s_id = 'fld-8651f7fbbfe0429690a9e0175b6eeaa4';
    var attribute_8_value_s_id = 'fld-56222dff96644bd9b9b3bd6d72d39db5';
    var attribute_9_value_s_id = 'fld-f4be5cac1b5d4ce48805765a2ff47a51';
    var attribute_10_value_s_id = 'fld-da36f2e28e1d4a8f8207a8a0e7f6b24d';
    record.setFieldValue(attribute_1_value_s_id, year);
    record.setFieldValue(attribute_2_value_s_id, manufacturer);
    record.setFieldValue(attribute_3_value_s_id, model);
    record.setFieldValue(attribute_4_value_s_id, gauge);
    record.setFieldValue(attribute_5_value_s_id, container);
    record.setFieldValue(attribute_6_value_s_id, era);
    record.setFieldValue(attribute_7_value_s_id, railroad);
    record.setFieldValue(attribute_8_value_s_id, brand);
    record.setFieldValue(attribute_9_value_s_id, collection);
    record.setFieldValue(attribute_10_value_s_id, tca_grade);
    form.saveAllChanges()

    }

    wc_attributes_update();

    While this works surprisingly well with regard to producing a proper CSV export, what I’ve found is that, as it’s currently scripted, the active record is saved immediately any time one of the “paired” fields is edited. This results in a “refresh” of sorts that results in my cursor being returned to the first field of the form. It’s functional, but grossly inefficient for data entry.

    I’m convinced there is a better method to perform this function, but having limited scripting experience, I’m hoping some of you that are more agile with TF may offer some better guidance. Since the “duplicate” columns’ ONLY purpose is for exporting (they are all hidden within TF), I tried to create a “form” script that I could execute on-demand prior to export (vs. my current “field” script that executes automatically any time data is added/changed in one of these fields). Sadly, I haven’t been able to get anything even close to doing that thus far.

    If there’s a way to have this field replication execute on-demand, or even a “back to the drawing board” alternative strategy, I’d be grateful and eager to hear anyone’s suggestions.

    Thanks in advance for any suggestions!

    Cheers

    #49112
    Glen Forister
    Participant

    I see the keys that will do the following on the Mac, but not on the iPhone.

    I assume this is probably doable with Scripts, because I don’t see any menu items that does this.
    Attached is a screen shot on my iphone of my last database “default view” for a file (FORM) which is akin to your creating an advanced search. Once one of these options is set when the file is opened, it would open with the selected options under a “STARTUP” menu.
    I’m specifically interested in the options on the picture which is when the FORM is opened it opens with the last record open for editing.

    • This topic was modified 2 years, 8 months ago by Glen Forister.
    Attachments:
    You must be logged in to view attached files.
    #49100

    In reply to: Prompt for input

    Daniel Leu
    Participant

    I have a little prompter helper library that makes it easier to use the Prompter, at least for simple cases. You can find it at: https://api.danielleu.com/public/tf5/v1/files/prompterHelper-v2.js

    Place the code in a form named Scripts and call it prompterHelper. Here is a little example:

    document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
    
    async function myFunction() {
      
      try {
      	await textPrompter('Enter date');
    	console.log("Text entered: " + prompterVar);
      } catch (errorText) {
      	// user clicked 'Cancel'
      	console.log('cancelled');
      	return;
      }
      
      // user clicked 'yes'
      // continue with function
      // main code here
      console.log('continue from yes');
    }
     
    myFunction();

    As you see, the entered text is stored in the variable prompterVar. As Brendan showed, this would need to be parsed in order to get date object.

    Cheers, Daniel

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

    #49097

    In reply to: Simple previous

    Daniel Leu
    Participant

    I don’t really understand what you would like to calculate. But here are my 2 cents:

    You get the error:
    > “Tot$/dwr: ReferenceError: Can’t find variable: previousRecord_total, line:(null)”
    because the variable previousRecord_total is not defined. It should be previousTotal and the statement should be a line lower.

    > var previous_total = previousRecord.getFieldValue($_grp);`
    getFieldValue() needs a field id and not a value.

    For the previous calculation, the field id is the id of the script. You can get it from the form inspector panel > field > select field and look for the ID under the description section.

    I would change as well how the first initial value for currentRecordIndex == 0 is handled:

    var previous_total = 0;
    if (currentRecordIndex > 0) {
       var previousRecord = records[currentRecordIndex-1];    
       previous_total = previousRecord.getFieldValue(totalId);
    }
    

    Now previous_total is initialized to 0. If there is an earlier record, it is set accordingly.

    With these changes, my field script now looks like this:

    function Add_Previous() {
        var $_dwr = record.getFieldValue('fld-c1faad7124f8400bbf9e55c477b101ef');
        var $_grp = record.getFieldValue('fld-72156bcc2515453d80a4649d30cb938f');
        var totalId = 'fld-9bc44cd8a52547fcab897dbfa04afcc2';
    	
        var records = form.getRecords();   // calls function getRecords()
        var currentRecordIndex = records.indexOf(record);
    
        var previous_total = 0;
        if (currentRecordIndex > 0) {
           	var previousRecord = records[currentRecordIndex-1];    
           	previous_total = previousRecord.getFieldValue(totalId);
        }
        
        console.log("dwr: " + $_dwr);
        console.log("grp: " + $_grp);
        console.log("previous total: " + previous_total);
       	
        var total = $_dwr + previous_total;	
        console.log("Total: " + total);
    	
        return total;
    }
    
    Add_Previous();

    Hope this helps!

    Cheers, Daniel

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

    #49094

    In reply to: Simple previous

    Glen Forister
    Participant

    I played with the script with different changes and it appears I think that,
    “Tot$/dwr: ReferenceError: Can’t find variable: previousRecord_total, line:(null)”

    This is past my diagnostic ability now, so I’ll attach the archive to save us both a lot of time possibly.
    Thanks.

    PS, I think I’m almost done getting my life back on track with functioning forms again after moving from HanDBase to TF. Now, I’ll try to researching JavaScript to see if I can get a handle on the basics which the preliminary videos and files just hinted at. Too much to learn quickly.

    Attachments:
    You must be logged in to view attached files.
    #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, 8 months ago by Daniel Leu.
    • This reply was modified 2 years, 8 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, 8 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.

Viewing 15 results - 571 through 585 (of 2,951 total)