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,131 through 2,145 (of 2,953 total)
  • Author
    Search Results
  • #38405
    Gary Beberman
    Participant

    I’m testing Tap Forms now, trying to use it to update an email list. I have two sources:

    – A master list of people
    – A related list with a smaller number of email addresses. Members of this list should be sent a specific kind of email. So, this relationship would be one-to-one, right? That is, if Tap Forms had that as an option. Many addresses in the master list, though would not have related records here. I coded it as a JOIN with “Show Inverse Relationship” checked.
    – In the future, there will likely be more of these lists for different email types. So, the same address could be linked to multiple times. But each relationship would still be one-to-one.

    The objective is to export the master list along with that additional field showing a person should receive that kind of email.

    I coded a calculation field in the master file as:

    IFNOTEMPTY(Still::Email;”Y”;””)

    I can see related records. But, the calculated field is blank. Any advice? Do I have to do this with scripts?

    Thanks!

    Gary

    #38381

    In reply to: Question on Note Field

    Brendan
    Keymaster

    Hi Rocky,

    I’m sorry but the Script function has no access to formatting the text within Note fields.

    Thanks,

    Brendan

    #38377
    Rocky Machado
    Participant

    I think I know the answer here, but thought I would ask. Is it possible to format data in a note field via code? Or when I create text and save it to a note field. Is it possible to send it tags that would format the data when creating via a script.

    Thanks, rocky

    #38372
    Martin Inchley
    Participant

    A simple Calculation (number) field is warming my brain!

    IF(Type = "Dividend";24;32)

    “Type” is the name of a Script field which contains “Dividend” or one of two other values.
    24 and 32 are two arbitrary numbers to help me sort things out.

    With this Calculation, all the records have 24 in the Calculation field, no matter whether Type contains “Dividend” or one of the other values.

    With IF(Type = "";24;32), all the records still show 24.
    With IF(TaxYear = "1718";24;32), all the records in Tax Year 1718 show 24. The others show 32, as expected.

    I can’t see what I’m doing wrong when referencing the field “Type”.

    #38335
    Martin Inchley
    Participant

    In multi-column view with “Show sections” enabled, when my records are sorted on a Date field, the sections are set automatically to include the records for each month. Is there a way of changing that default section period to, say, a year or a day?

    I have a Script field that holds a record’s applicable tax year in 4-digit format (e.g. 1819). When I sort on that field to get some totals for a tax year, the multi-column view shows no sections at all. This is all regardless of showing/hiding Group summaries, and showing/hiding the Calculations row. Nor do sections show up if I sort (e.g.) on account number

    #38332
    Marcus
    Participant

    Thanks, Brendan.
    I tried that already by using var.toFixed(2),
    but this is running in a TypeError: toFixed is not a function.
    This happens only when the script is running over such an affected value, for other values toFixed is working.

    #38326
    Brendan
    Keymaster

    It’s a byproduct of the use of the Objective-C doubleValue method. The formatting and rounding according to the decimal places and Number Format settings doesn’t happen until display time. But internally the value is as it is. You would need to perform some JavaScript rounding of the values yourself if you need to do that.

    #38306
    Brendan
    Keymaster

    I know where you got this from:

    https://stackoverflow.com/questions/27746418/send-email-with-attachment-using-javascript-for-automation

    But that’s JavaScript for Automation. That is, from AppleScript (but using JavaScript instead of the AppleScript language).

    That won’t work from within JavaScriptCore, which is what Tap Forms uses.

    #38305
    Brendan
    Keymaster

    Hi Eddy,

    Did you try this from within Tap Forms? I just tried, but I get Can't find variable Application error. I’m not sure that Application is supported from within the JavaScriptCore framework.

    #38303
    Brendan
    Keymaster

    I don’t have an exact timeline right now. I’m just trying to fix up a memory issue with running scripts. The memory isn’t being released properly. Hopefully not too much longer.

    #38298
    Sam Moffatt
    Participant

    Based on a reply I added on the time delay post I wrote a while back, I decided to clean up and better document the script.

    There are three functions:

    • delay – simple spin lock delay mechanism for blocking execution for duration milliseconds.
    • rateLimitedDelay – ensure that a script blocks for at least minTime milliseconds since the last execution tracked by key.
    • rateLimitedCallback – non-blocking method to execute callback no more frequently than minTime milliseconds since the last execution tracked by key.

    The first use case is pretty simple: call it and wait until the duration expires. The second one is for ensuring you don’t go through a code path too quickly but if you haven’t called it lately it will immediately call it. The third one is used to optionally execute callback if you haven’t executed it in the last minTime milliseconds which is useful for avoiding spamming log messages or other similar events. It enables you to put in a callback but if it’s recently executed to immediately skip it (it’s not blocking). I built this to support a REST progress interface for ensuring it didn’t post updates more frequently than once every few seconds.

    This script uses a pattern I’m adopting of including a simple test case at the end. If you execute the script directly, it’ll run the test case as a sample of how to run. This means when you import you need to also define a variable called PARENT_SCRIPT which is used to disable the test. Technically you can set PARENT_SCRIPT to any value but I use the format FORM NAME::SCRIPT NAME:

    var PARENT_SCRIPT = 'Products::Update SKUs for Product';
    document.getFormNamed('Script Manager').runScriptNamed('Rate Limiter');
    

    Test case:

    	console.log('Message 1 at ' + new Date());
    	rateLimitedDelay('test');
    	rateLimitedDelay('test');
    	rateLimitedCallback('callback', function() { console.log('Callback 1: ' + new Date()) }); 
    	console.log('Message 2 at ' + new Date());
    	delay(3000);
    	rateLimitedCallback('callback', function() { console.log('Callback 2: ' + new Date()) });
    	rateLimitedDelay('test');
    	console.log('Message 3 at ' + new Date());
    	delay(6000);
    	rateLimitedCallback('callback', function() { console.log('Callback 3: ' + new Date()) });
    	console.log('Message 4 at ' + new Date());
    	rateLimitedDelay('test');
    	console.log('Message 5 at ' + new Date());
    	rateLimitedCallback('callback', function() { console.log('Callback 4: ' + new Date()) });
    

    Here’s the full script:

    // ========== Rate Limiter Start ========== //
    // NAME: Rate Limiter
    // VERSION: 1.0.0
    // CHANGELOG:
    //   1.0.0: Initial release.
    /**
     * Rate Limiter module provides utilities to limit and delay
     * over time.
     */
    if (typeof rateLimiter === 'undefined')
    {
    
    	var rateLimiter = {};
    	
    	/**
    	 * Spin lock delay mechanism.
    	 *
    	 * This will block execution until the time limit.
    	 *
    	 * @param {integer} duration - The length of the delay in milliseconds.
    	 */ 
    	function delay(duration)
    	{
    		let now = new Date();
    		let future = now.getTime() + duration;
    		while((new Date()).getTime() < future) { }
    	}
    	
    	/**
    	 * Blocking rate limited delay mechanism.
    	 *
    	 * This will block a request until a minimum time has been elapsed.
    	 * If based on the last execution of the `key`, `minTime` milliseconds
    	 * have not elapsed, this will block until that time has elapsed.
    	 *
    	 * `key` is shared with rateLimitedCallback.
    	 *
    	 * @param {string}  key - The key to validate the last execution.
    	 * @param {integer} minTime - The minimum amount of time between execution.
    	 */
    	function rateLimitedDelay(key, minTime = 5000)
    	{
    		if (typeof rateLimiter[key] === 'undefined')
    		{
    			rateLimiter[key] = 0;
    		}
    		let now = new Date().getTime();
    		let nextExecution = rateLimiter[key] + minTime;
    		if (now < nextExecution)
    		{
    			delay(nextExecution - now);
    		}
    		rateLimiter[key] = new Date().getTime();
    	}
    
    	/** 
    	 * Non-blocking rate limited callback executor.
    	 *
    	 * This will execute `callback` only if `callback` hasn't been 
    	 * executed as `key` for at least `minTime` milliseconds since
    	 * the last execution. If it has been executed then it will not
    	 * execute this instance.
    	 *
    	 * `key` is shared with `rateLimitedDelay`.
    	 *
    	 * @param {string}   key - The key to validate the last execution.
    	 * @param {function} callback - Callback to execute.
    	 * @param {integer}  minTime - The minimum amount of time between executions.
    	 */
    	function rateLimitedCallback(key, callback, minTime = 5000)
    	{
    		if (typeof rateLimiter[key] === 'undefined')
    		{
    			rateLimiter[key] = 0;
    		}
    		let now = new Date().getTime();
    		let nextExecution = rateLimiter[key] + minTime;
    		if (now > nextExecution)
    		{
    			callback();
    			rateLimiter[key] = new Date().getTime();
    		}
    	}
    }
    
    // Tests
    if (typeof PARENT_SCRIPT === 'undefined')
    {
    	console.log('Message 1 at ' + new Date());
    	rateLimitedDelay('test');
    	rateLimitedDelay('test');
    	rateLimitedCallback('callback', function() { console.log('Callback 1: ' + new Date()) }); 
    	console.log('Message 2 at ' + new Date());
    	delay(3000);
    	rateLimitedCallback('callback', function() { console.log('Callback 2: ' + new Date()) });
    	rateLimitedDelay('test');
    	console.log('Message 3 at ' + new Date());
    	delay(6000);
    	rateLimitedCallback('callback', function() { console.log('Callback 3: ' + new Date()) });
    	console.log('Message 4 at ' + new Date());
    	rateLimitedDelay('test');
    	console.log('Message 5 at ' + new Date());
    	rateLimitedCallback('callback', function() { console.log('Callback 4: ' + new Date()) });	
    }
    // ========== Rate Limiter End ========== //
    
    #38295

    In reply to: Table row index number

    Sam Moffatt
    Participant

    That means there is no way to get a value from a parent record from the table field?

    I’ve been playing with script fields inside table fields and they’re a little quirky. Does the recalculate formulas button properly refresh script/calc fields inside a table? It doesn’t seem like they do. It also took a couple of saves before my script field would properly update to reflect changes.

    If the answer to the first question is yes, then a script like this will resync them:

    var hourly_rate = record.getFieldValue('fld-47aef2ed3cda40d18ff896959a31062c');
    var table = record.getFieldValue('fld-30d04e6103ad4ba8ac1a2149fbfde064');
    
    for(target of table)
    {
    	target.setFieldValue('fld-b7aca38a1e83483bbe94c7b6cf850f18', hourly_rate);
    }

    This is a little heavy because it runs every time a change is made to either field (or for the table, any column of any row) but it does work.

    #38292

    In reply to: Table row index number

    Brendan
    Keymaster

    So there’s something different that happens for Table field sub-fields and sub-records when running a script. When you run the script in the Script Editor, record actually does refer to the parent form’s currently selected record.

    However, when you modify a sub-field value for a sub-record within a Table field in which you have a Script Field, Tap Forms will use the correct Table field’s record in place of the record reference in the script.

    This works because when you type in a value into a sub-field of your Table field, Tap Forms knows what that currently selected record is. The JSContext is updated with the currently selected Table field sub-record and the script is evaluated.

    Hope that clears it up.

    Sorry I missed seeing the reply to this message.

    #38269
    Martin Inchley
    Participant

    OK, I have some progress – though not an answer for why the scripts suddenly stopped working.

    The second of the two scripts above toggles the checkbox if the Payment Date field is filled or emptied. I’ve been treating the checkbox field as a Boolean and assuming that using True/False or 1/0 was immaterial.

    But if I use “1” and “0” for the value to be inserted, rather than “True” or “False”, then the checkbox responds correctly in the LtF field on the linked form.

    I created a new check mark field and used a script to show its value. Before any action, the console reported its value as “False”. But checking it gave a value of “1”. Unchecking it gave “0”. Thereafter it stuck with 1 and 0.

    Since my scripts worked initially on their own form, it seems that these checkbox fields will normally work OK with “True” and “False”. But (so far), they need to be using 1 and 0 to be consistent within my LtF field. I’ve tested them both with and without quote marks around the digit – both work fine.

    #38266
    Martin Inchley
    Participant

    Hm…

    Clicking to another record – in either the main form or the Link-to-Form field – makes no difference.

    I’ve written a script to present the info in the console – still the checkbox stays unchecked. I’ve checked the real status of the checkbox field with a calculation field – it agrees with the script result in the console in showing that the checkbox value is true / 1, even though the checkbox is not displaying that in the Link-to-Form field.

    And then…

    Playing with the LtF field, I removed certain fields from showing. When I saved that, TF crashed and quit (I’m used to that – hopefully the next release will have fixed it). When I re-started and went to the native form (not the linked one with the LtF field), the scripts (in my first post above) for setting the date and toggling the checkbox no longer worked. I did a proper clean re-start – no effect.

    What got them working again was bringing up the console. As soon as I did that, they were fine. Grrrr…

    So I’m less than happy and, I’m afraid, beginning to lose confidence in the system as a solution for a target user who just needs everything to work. Financial details are a sensitive area…

Viewing 15 results - 2,131 through 2,145 (of 2,953 total)