Search Results for 'script'
-
Search Results
-
Topic: Calculated Field with Join
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
Topic: Question on Note Field
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
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.
WithIF(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”.
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
Topic: Rate Limiter Script
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
durationmilliseconds. - rateLimitedDelay – ensure that a script blocks for at least
minTimemilliseconds since the last execution tracked bykey. - rateLimitedCallback – non-blocking method to execute
callbackno more frequently thanminTimemilliseconds since the last execution tracked bykey.
The first use case is pretty simple: call it and wait until the
durationexpires. 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 executecallbackif you haven’t executed it in the lastminTimemilliseconds 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_SCRIPTwhich is used to disable the test. Technically you can setPARENT_SCRIPTto any value but I use the formatFORM 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 ========== // - delay – simple spin lock delay mechanism for blocking execution for