Andrew Reid

My feedback

  1. 1 vote
    Vote
    Sign in
    (thinking…)
    Sign in with: facebook google
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    3 comments  ·  TrackVia API & App Scripts » App Script  ·  Flag idea as inappropriate…  ·  Admin →
    Andrew Reid commented  · 

    Hi George -

    Scripts require a database action in order to run. So the user must be either adding or updating a record in order to trigger a script. There's not a situation in which a script could be triggered where they're neither the creator nor the updater.

    Andrew Reid commented  · 

    Hi George-

    You can access either the Created By User (for record inserts) or the Last User (for record updates) via script.

    To pull that Last User value into a variable on record update, you'd use the following syntax:
    Map userVariable = currentValues["Last User"] as Map

    Once you've accessed the user record, you can either store that value in an Application User field or parse it via script to get the user's name or email address.

  2. 1 vote
    Vote
    Sign in
    (thinking…)
    Sign in with: facebook google
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    1 comment  ·  TrackVia API & App Scripts » App Script  ·  Flag idea as inappropriate…  ·  Admin →
    Andrew Reid commented  · 

    Hi Steve,

    When you get a list of records via an App Script, they'll be typically be sorted by the default sort. which is record created date. If you wish to sort by some other field in the record then it’s probably best to use the Groovy Spaceship Operator (http://groovy-lang.org/operators.html#_spaceship_operator).

    In the example below, I’m generating a list of child records from their common parent and then sorting them by a Date field in the child records. The second list (called “sortedKids”) returns all those children with the earliest date first.

    List<Map> kids = getChildren("Child Table", "Parent") as List<Map>
    List<Map> sortedKids = kids.sort({ a,b -> a['Date'] as Date <=> b['Date'] as Date }) as List<Map>

    As shown above, this does require casting objects as Dates in order for the sort to compile and execute properly.

Feedback and Knowledge Base