Joshua's Cheatsheets - Android Automagic App Cheatsheet and Notes
Light
help

Resources

Install: Google Play

Important resources:

Automagic - How Do I...

  • Print something to the global console

  • Initialize an object:

    • You have to start with empty object, using fromJSON

      fromJSON('{}')
      myObj['myKey'] = 'myVal';
  • Check if a variable has a value / is not null

    • Use getValue - getValue(String variableName, Object, defaultIfUndefined)

      isDefined = getValue('myVariable', false);
      if (isDefined) {
      // Do something
      }
  • Use time comparisons and date utilities

    • Triggers will add a flow variable, triggertime, which is stored as a Number MS timestamp

      • Although it is a Number, it works with functions like addDay().
    • There are multiple built-in functions for getting date/time info:

      • Date getDate() (and variations) - get current date & time
      • Number getUptimeMillis() - MS since boot, excluding sleep time
      • Number getElapsedRealtimeMillis() - MS since boot, including sleep time
    • Use dateformat for formatting timestamps
    • There are multiple built-in functions for offsetting date and time

      • Date add___(Date d, Number a)

        • addDays(d, a)
        • addHours(d, a)
        • addMinutes(d, a)
        • addSeconds(d, a)
  • Persist a value across executions

    • There are many reasons why you might want to persist a value across executions; for example, for multiple counters, to track last execution time(s), or to cache API responses.
    • Approaches

      • By far, the easiest way to persist a value is with a Global variable. These are shared across flows, and persisted in non-volatile memory (reloaded if you restart Automagic).

        • Simply prefix your variable name with global_, such as global_myVar = "my string";
        • Be careful about conflicting global variable names
      • Writing and reading out of text files might be a decent approach for persistent large amount of data (such as stringified JSON) (limit of 1MB)

Automagic Example Script - Throttling Executions

This code can be used in an Expression condition step, to throttle executions of the flow to once per every 10 minutes.

throttleMins = 10;
lastExecutedAt = getValue('global_lastExecAct', 0);
minSinceLastExecuted = ((triggertime - lastExecutedAt) / 1000 / 60);
if (minSinceLastExecuted > throttleMins) {
	global_lastExecAct = triggertime;
	return true;
}
else {
	log("Skipping execution - last executed " + minSinceLastExecuted + " min. ago");
	return false;
}
Markdown Source Last Updated:
Tue Jun 23 2020 19:52:31 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Tue Jun 23 2020 19:51:04 GMT+0000 (Coordinated Universal Time)
© 2020 Joshua Tzucker, Built with Gatsby