List Functions#

  • fn.group_by_larger_than_count: Returns either a list of instance names or dictionary instance names with count values, given parameters:

    • model type

    • model attribute

    • greater than an input numeric value of the attribute

    • specified search direction in hierarchy: up or down

    Example

    Output

    Context hierarchy: sys, list of more than 1 of iso_country_code in data/Countries, search down

    • display as dictionary:

    {{ fn.group_by_larger_than_count data/Countries,
                                     iso_country_code,
                                     down,1,dict }}
    
    • display as list:

    {{ fn.group_by_larger_than_count data/Countries,
                                     iso_country_code,
                                     down,1,list }}
    
    [
     {
      "iso_country_code": "AUS",
      "count": 2
     },
     {
      "iso_country_code": "CHN",
      "count": 2
     }
    ]
    
    
    
    [
     "AUS",
     "CHN"
    ]
    
  • fn.is_list: Return true or false if the parameter is a list or not.

  • fn.list_index: Return a specified item from a list. Zero is the first item.

    Example

    Output

    {{fn.list_index 2,data.Countries.country_name}}
    

    “Canada” if this is the third item.

  • fn.list_index_item: Return the position of item in list.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    {{ fn.list_index_item 42,macro.MACRO1 }}
    
    2
    
  • fn.list_count: Return the number of items in a list. Note that if the list is known and empty, the count is 0, but if the list is not known, then the count is 1, because the returned message string count is 1.

    Example

    Output

    {{fn.list_count data.Countries}}
    
    
    
    {{fn.list_count input.does_not_exist}}
    
    {{fn.list_count non_existant_namespace.does_not_exist}}
    
    25 if the
    list has
    25 items.
    
    0
    
    1
    
  • fn.list_count_item: Return the number of times item is in a list.

    Example

    Output

    MACRO1={# data.Countries.international_access _prefix #}
    
    
    {{ fn.list_index_item 00,macro.MACRO1 }}
    
    19
    
  • fn.list_in: Return true or false if item is in a list or not.

    Example

    Output

    {{fn.list_in 'AUS',data.Countries.iso_country_code}}
    
    
    {{fn.list_in 'AUZ',data.Countries.iso_country_code}}
    
    true
    
    
    false
    
  • fn.list_contain: Return true or false if item is a substring of an input context

    or is in a list or not.

    Example

    Output

    {
        "input": {
            "list": [
                "AUS",
                "BHR"
            ],
            "key": "aaAUZa"
    
        }
    }
    
    {{fn.list_contain 'AUS',input.list }}
    
    
    {{fn.list_contain 'AUZ',input.key }}
    
    true
    
    
    true
    
  • fn.list_contain_pattern: Given a pattern or list of patterns as well as a target list of items, return the matching list of items from the target list of items.

    If an invalid pattern is input (or not matched), then it is ignored.

    Example

    Output

    {
        "input": {
            "pattern_list": [
                "SEP",
                "BAT"
            ],
            "desk_phones": [
                "SEP9999ABAB0000",
                "BOT123123",
                "TCT123123",
                "BAT9999ABAB0000"
            ]
    
        }
    }
    
    {{fn.list_contain_pattern SEP, input.desk_phones }}
    
    {{fn.list_contain_pattern input.pattern_list, input.desk_phones }}
    
    ["SEP9999ABAB0000"]
    
    ["SEP9999ABAB0000",
     "BAT9999ABAB0000"]
    
  • fn.list_append: Returns a list with item appended.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    {{fn.list_append 999,macro.MACRO1 }}
    
    ['40', '41',
     '42', '43',
     '999']
    
  • fn.list_pop: Return the last item of the list.

    Example

    Output

    MACRO1={# fn.sequence  40,43 #}
    
    {{fn.list_pop macro.MACRO1}}
    
    "43"
    
  • fn.list_insert: Return a list with item inserted at position.

    Example

    Output

    MACRO1={# fn.sequence  40,43 #}
    
    {{fn.list_insert 1,999,macro.MACRO1 }}
    
    ['40', '999',
     '41', '42',
     '43']
    
  • fn.list_insert_no_dup: Return a list with item inserted at position and all duplicates ignored.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    MACRO7={# fn.sequence  39,41 #}
    
    {{fn.list_insert_no_dup  macro.MACRO1,macro.MACRO7}}
    
    ['40','41',
     '42','43',
     '39']
    
  • fn.list_remove: Return a list with all instances of item or list of items removed.

    Example

    Output

    MAC1={# fn.sequence 40,43 #}
    MAC7={# fn.sequence 40,41 #}
    MAC3={{fn.list_insert 1,43,macro.MAC1 }}
    
    
    {{fn.list_remove 43,macro.MAC3 }}
    
    
    {{fn.list_remove macro.MAC7,macro.MAC1 }}
    
    ['40','41',
     '42']
    
    ['42','43']
    
  • fn.list_remove_pattern: Given a pattern or list of patterns as well as a target list of items, remove the matching list of items from the target list of items.

    If an invalid pattern is input (or not matched), then it is ignored.

    Example

    Output

    {
        "input": {
            "pattern_list": [
                "SEP",
                "BAT"
            ],
            "desk_phones": [
                "SEP9999ABAB0000",
                "BOT123123",
                "TCT123123",
                "BAT9999ABAB0000"
            ]
    
        }
    }
    
    {{fn.list_remove_pattern SEP, input.desk_phones }}
    
    {{fn.list_remove_pattern input.pattern_list, input.desk_phones }}
    
    ["BOT123123",
     "TCT123123",
     "BAT9999ABAB0000"]
    
    ["BOT123123",
    "TCT123123"]
    
  • fn.list_remove_dup_dict: Given a list of dictionaries, a sort key and an optional sort direction, return a list with the duplicate entries removed, sorted by the specified sort direction or if not specified, sorted in ascending order.

    Example

    Output

    {
      "input": {
       "dupl":
      [
        {
            "country_name": "Canada",
            "iso_country_code": "CAN"
        },
        {
            "country_name": "China",
            "iso_country_code": "CHN"
        },
        {
            "country_name": "China",
            "iso_country_code": "CHN"
        },
        {
            "country_name": "Switzerland",
            "iso_country_code": "CHE"
        }
      ]
      }
    }
    
    
    {{ fn.list_remove_dup_dict input.dupl,
       country_name }}
    
    {"dupl":
     [
      {
          "country_name": "Canada",
          "iso_country_code": "CAN"
      },
      {
          "country_name": "China",
          "iso_country_code": "CHN"
      },
      {
          "country_name": "Switzerland",
          "iso_country_code": "CHE"
      }
     ]
    }
    
  • fn.list_remove_dup: Return a list with all instances of item or list of items removed, including duplicates.

    Example

    Output

    Given the following list is the result of the regex for iso_country_code:

    {# data.Countries.iso_country_code |
       iso_country_code:/AU/ #}
    
    
    
    {# fn.list_remove_dup data.Countries.iso_country_code |
       iso_country_code:/AU/ #}
    
    ['AUS','SAU',
      'AUS','AUS']
    
    ['AUS','SAU']
    
  • fn.list_remove_nulls: Return a list with all null instances in a list of items removed.

    Example

    Output

    {"pwf": {
     "my_list": [1, null, 2,"test", 3, null]
     }
    }
    
    
    {{ fn.list_remove_nulls pwf.my_list }}
    
    [1,2,"test",3]
    
  • fn.list_reverse: Return a list that is the reverse of a given list.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    {{fn.list_reverse macro.MACRO1}}
    
    ['43','42',
     '41','40']
    
  • fn.list_extend: Return a list that is an extension of list 1 with list 2.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    MACRO9={# fn.sequence 50,52 #}
    
    {{fn.list_extend macro.MACRO1,macro.MACRO9 }}
    
    ['40', '41',
     '42', '43',
     '50', '51',
     '52']
    
  • fn.list_extend_no_dup: Return the concatenation of list1 and list2, ignoring duplicates.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    MACRO8={# fn.sequence 42,45 #}
    
    {{fn.list_extend_no_dup macro.MACRO1,macro.MACRO8 }}
    
    ['40','41',
     '42','43',
     '44','45']
    
  • fn.sequence: Return a sequence of numbers running from the first value to the second value, optionally padded with zeroes to be the length of a third value.

    Example

    Output

    {# fn.sequence 40,43 #}
    
    
    {# fn.sequence 110,100,4 #}
    
    ['40','41',
     '42','43']
    
    ['0110','0109',
     '0108',
     '0107','0106',
     '0105','0104',
     '0103','0102',
     '0101','0100']
    
  • fn.list_set_symdiff: Given two lists as input, return the list of items that are not common to both lists.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    MACRO2={# fn.sequence 41,45 #}
    
    {{ fn.list_set_symdiff macro.MACRO1,macro.MACRO2 }}
    
    ['40','44','45']
    
  • fn.list_sort: Return a sorted list; by ascending (A) or descending (D) order.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    
    {{fn.list_sort macro.MACRO1,D}}
    
    
    {{fn.list_sort macro.MACRO1,Descending}}
    
    
    MACRO5={# fn.sequence 110,108,4 #}
    
    
    {{fn.list_sort macro.MACRO5,A}}
    
    ['43','42',
     '41','40']
    
    ['43','42',
     '41','40']
    
    ['0110','0109',
     '0108']
    
    ['0108','0109',
     '0110']
    
  • fn.one: Return a single result from a list. This is used to convert a single element list to a string.

    If fn.one is called with a string, it returns the string unchanged. The string can be a macro that might get the value of another attribute from a context, such as input.some_variable.

    Example

    Output

    {{fn.one data.Countries.iso_country_code |
      emergency_access_prefix:'112'}}
    
    
    {{fn.one abc}}
    

    A single result, e.g. ‘DEU’

    'abc'
    
  • fn.as_list: Return a string result as a list. If fn.as_list is called with a string, it returns a list. Again, abc could be a macro that resolves to the value of an attribute in its context.

    Example

    Output

    {{fn.as_list data.Countries.country_name | country_name:'China'}}
    
    {{fn.as_list abc}}
    
    ['China']
    
    ['abc']
    
  • fn.list_empty: Returns an empty list

    Example

    Output

    {{fn.list_empty}}
    
    []
    
  • fn.list_set_intersect: Given two lists, return the intersection as a list.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    MACRO2={# fn.sequence 41,42 #}
    
    {# fn.list_set_intersect macro.MACRO1,macro.MACRO2 #}
    
    ['41','42']
    
  • fn.list_set_union: Given two lists, return the union as a list.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    MACRO2={# fn.sequence 41,45 #}
    
    {# fn.list_set_union macro.MACRO1,macro.MACRO2 #}
    
    ['40','41',
     '42','43',
     '44','45']
    
  • fn.list_set_left: Given two lists, return a list of items in the left list only.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    MACRO2={# fn.sequence 41,45 #}
    
    {# fn.list_set_left macro.MACRO1,macro.MACRO2 #}
    
    ['40']
    
  • fn.list_set_right: Given two lists, return a list of items in the right list only.

    Example

    Output

    MACRO1={# fn.sequence 40,43 #}
    MACRO2={# fn.sequence 41,45 #}
    
    {# fn.list_set_right macro.MACRO1,macro.MACRO2 #}
    
    ['44','45']
    
  • fn.list_filter_fields: Given a model name, two field names, hierarchy PKID and a list of field values from one of the fields, return the list of values from the other field. The hierarchy PKID parameter must be passed in as a PKID of the hierarchy node.

    Example

    Output

    {
        "input": {
            "list": [
                "AUS",
                "BHR"
            ]
        }
    }
    
    
    {# fn.list_filter_fields data/Countries,
        8c0hfle2c0deab00da595101,iso_country_code,
        country_name,input.list #}
    
    [
      "Australia",
      "Bharain"
    ]
    
  • fn.flatten_list_of_lists: Given a list of lists, return a single, flattened list.

    Example

    Output

     {
         "input": {
             "args": [
                 [
                     "AAA"
                 ],
                 [
                     "BBBB",
                     "CCCC"
                 ],
                 [
                     "DD"
                 ]
             ]
         }
     }
    
    {# fn.flatten_list_of_lists input.args #}
    
    [
      "AAA",
      "BBBB",
      "CCCC",
      "DD"
    ]
    
  • fn.flatten_nested_lists: Given a list of scalars and lists (which could have different levels of nesting), return a single, flattened list.

    Example

    Output

     {
         "input": {
             "args": [
                 "77174011",
                 [
                  "77174021",
                  "77174080",
                  [
                   "55555",
                   "1",
                  ]
                 ],
                 "12345"
             ]
         }
     }
    
    {{ fn.flatten_nested_lists input.args }}
    
    [
      "77174011",
      "77174021",
      "77174080",
      "55555",
      "1",
      "12345"
    ]
    
  • fn.modulo_list: Given a list and divisor, return a modulo list: list items that leave no remainder after divided. The input list is typically a directory number list and the divisor is an E164 range.

    Example

    Output

     {
         "input": {
             "args": [
                 [
                     "100",
                     "12000",
                     "13000",
                 ]
         }
     }
    
    {{ fn.modulo_list input.args,1000 }}
    
    [
      "12000",
      "13000"
    ]
    
  • fn.get_tvpair_list: Given an input list of dictionaries containing repeated pairs of equal type and a title-value mapping of these pairs, return a list of objects of these pairs where the pairs are mapped to title and value pairs that can for example be shown in a GUI rule in a choices drop-down list on a GUI form.

Example

Output

{
  "input": {
   "dataList" = [
         {
             "timeZoneCode": "10",
             "timeZoneName": "Africa/Bissau"
         },
         {
             "timeZoneCode": "100",
             "timeZoneName": "America/Noronha"
         },
         ...
         ...
      ]
   }
}

{{ fn.get_tvpair_list input.dataList,
   title:timeZoneName,value:timeZoneCode }}
[
  {
    "value": "10",
    "title": "Africa
              /Bissau"
  },
  {
      "value": "100",
     "title": "America
             /Noronha"
  },
 ...
 ...
]
  • fn.list_batch: Given a batch size and list as parameters, return the list as a batch of lists - each with size batchsize. If list cannot divide into batchsize, then the last list item is the remainder.

    The function is useful when processing large lists, which can then first be split into smaller batches.

    Example input:

    {
      "input": {
        "list": [
          "foo",
          "bar",
          "baz",
          "qux",
          "quux"
        ]
      }
    }
    

Example

Output

input.list as above (5-item list):

{{ fn.list_batch 2,input.list }}

batch of 2-item lists:

[
  [
    "foo",
    "bar"
  ],
  [
    "baz",
    "qux"
  ],
  [
    "quux"
  ]
]