Conversion functions
--------------------


.. index:: Macro function;fn.pkid_to_bkey

* *fn.pkid_to_bkey*:  Given a pkid, return the business key.  

.. index:: Macro function;fn.bkey_to_pkid

* *fn.bkey_to_pkid*:  Given a business key, return the pkid    
  Provide the data type as an argument.   

.. index:: Macro function;fn.from_business_key_format

* *fn.from_business_key_format*: Convert a field business
  key string format to a list

.. index:: Macro function;fn.as_int

* *fn.as_int*: Given a string, return an integer.      

.. index:: Macro function;fn.as_string

* *fn.as_string*:  Given an integer, return a string.      

.. index:: Macro function;fn.as_bool

* *fn.as_bool*: Given strings "True", "TRUE", "T", "t", 
  "1", return True. Given strings "False", "FALSE", "F",    
  "f", "0", return False.                 


* *fn.as_list*: Given input, return it as a list.      
  List input is returned as is.          

.. index:: Macro function;fn.int_to_hex

* *fn.int_to_hex*: Return the hexadecimal value of an integer. 
  Application example: for gateways that use hexadecimal values for port numbers.
   
.. index:: Macro function;fn.hex_to_int

* *fn.hex_to_int*: Return the integer value of a hexadecimal value.
  Application example: for gateways that use hexadecimal values for port numbers.
   
.. index:: Macro function;fn.getMajorMinorVersion

* *fn.getMajorMinorVersion*: Given a version in various formats, return a version of the 
  format <major>.<minor>.

.. index:: Macro function;fn.list_to_string

* *fn.list_to_string*: Given a list as input, return the list as a string.

  Note the following in the output - refer to the example below: 

  * strings in the list will be prefixed with a Unicode character ``u``
  * the "``[``" and "``]``" as well as the commas between list items are 
    included in the converted string

.. index:: Macro function;fn.list_items_to_string

* *fn.list_items_to_string*: Given a list as input (strings or integers),
  return each item as a string.

  Only simple lists are supported.

.. index:: Macro function;fn.list_items_to_int

* *fn.list_items_to_int*: Given a list of integers as input, return each item as a string.

  Only simple lists are supported.

  Only lists of integers are supported.



Examples:

.. tabularcolumns:: |p{9cm}|p{6cm}|


+----------------------------------------------+-----------------------------------+
|  Example                                     | Output                            |
+==============================================+===================================+
| ::                                           | ::                                |
|                                              |                                   |
|    macro: USA_pkid =                         |    "[u'United States of America', |
|     {{data.Countries.__pkid                  |       u'USA', u'']"               |
|      iso_country_code:USA}}                  |                                   |
|                                              |                                   |
|    {{fn.pkid_to_bkey macro.USA_pkid}}        |                                   |
+----------------------------------------------+-----------------------------------+
| ::                                           | ::                                |
|                                              |                                   |
|    macro: a_country_bkey =                   |    "52d3eba8893d57373f842acb"     |
|     {{data.Countries.__bkey                  |                                   |
|       __pkid:macro.USA_pkid}}                |                                   |
|                                              |                                   |
|    {{fn.bkey_to_pkid  macro.a_country_bkey,  |                                   |
|      data/Countries}}                        |                                   |
+----------------------------------------------+-----------------------------------+
| context data:                                |  ::                               |
|                                              |                                   |
|                                              |      [                            |
| ::                                           |        "10.110.21.101",           |
|                                              |        "8443",                    |
|                                              |        "hcs.CS-P.CS-NB.AAAGlobal" |
|    {                                         |                                   |
|        "self": {                             |      [                            |
|            "bk": "[\"10.110.21.101\",        |                                   |
|         \"8443\",                            |                                   |
|         \"hcs.CS-P.CS-NB.AAAGlobal\"]"       |                                   |
|        }                                     |                                   |
|    }                                         |                                   |
|                                              |                                   |
| function:                                    |                                   |
|                                              |                                   |
| ::                                           |                                   |
|                                              |                                   |
|    {{ fn.from_business_key_format self.bk }} |                                   |
+----------------------------------------------+-----------------------------------+



.. tabularcolumns:: |p{9cm}|p{6cm}|


+----------------------------------------------+-------------------------------------+
|  Example                                     | Output                              |
+==============================================+=====================================+
| ::                                           | ::                                  |
|                                              |                                     |
|    {{fn.as_int "1"}}                         |    1                                |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {{fn.as_string 12345}}                    |     "12345"                         |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {{fn.as_bool "T"}}                        |    true                             |
|                                              |                                     |
|    {{fn.as_bool "0"}}                        |    false                            |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|   {#fn.as_list foo bar#}                     |    ['foo bar']                      |
|                                              |                                     |
|   {#fn.as_list 'foo,bar'#}                   |    ['foo,bar']                      |
|                                              |                                     |
|   {#fn.as_list ['foo','bar']#}               |    ['foo','bar']                    |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {{fn.int_to_hex 255}}                     |    ff                               |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {{fn.hex_to_int ff}}                      |    255                              |
+----------------------------------------------+-------------------------------------+


.. tabularcolumns:: |p{9cm}|p{6cm}|


+----------------------------------------------+-------------------------------------+
|  Example                                     | Output                              |
+==============================================+=====================================+
| ::                                           | ::                                  |
|                                              |                                     |
|   {{ fn.getMajorMinorVersion 10.5(4) }}      |    10.5                             |
|                                              |                                     |
|   {{ fn.getMajorMinorVersion 11.5(1) SU1 }}  |    11.5                             |
|                                              |                                     |
|   {{ fn.getMajorMinorVersion 11.5.3 }}       |    11.5                             |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {"pwf": {                                 |                                     |
|     "my_list": [1, null, 2,"test", 3, null]  |                                     |
|     }                                        |                                     |
|    }                                         |                                     |
|                                              |                                     |
|                                              |                                     |
|    {{ fn.list_to_string pwf.my_list }}       |    "[1, None, 2, u'test', 3, None]" |
|                                              |                                     |
|                                              |                                     |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {"pwf": {                                 |                                     |
|     "my_list": [1, 2, "3", 4]                |                                     |
|     }                                        |                                     |
|    }                                         |                                     |
|                                              |                                     |
|                                              |                                     |
|    {{ fn.list_items_to_string pwf.my_list }} |    ['1', '2', '3', '4']             |
|                                              |                                     |
|                                              |                                     |
+----------------------------------------------+-------------------------------------+
| ::                                           | ::                                  |
|                                              |                                     |
|    {"pwf": {                                 |                                     |
|     "my_list": [1, 2, "3", 4]                |                                     |
|     }                                        |                                     |
|    }                                         |                                     |
|                                              |                                     |
|                                              |                                     |
|    {{ fn.list_items_to_int pwf.my_list }}    |    [1, 2, 3, 4]                     |
|                                              |                                     |
|                                              |                                     |
+----------------------------------------------+-------------------------------------+




.. |VOSS Automate| replace:: VOSS Automate
.. |Unified CM| replace:: Unified CM
