Object Functions ---------------- .. index:: Macro function;fn.is_object * *fn.is_object*: Return true or false if the parameter is an object or not. .. index:: Macro function;fn.object_keys * *fn.object_keys*: Given an object and additional optional parameter, return the list of keys that match the parameter value, or all the keys if no parameter value is given. Example object: :: { "input": { "object": { "boolean_1": true, "boolean_2": false, "boolean_3": true, "string_1": "1", "string_1_dup": "1", "string_2": "2", "integer_1": 1, "integer_1_dup": 1, "integer_2": 2 } } Examples: .. tabularcolumns:: |p{8cm}|p{7cm}| +------------------------------------------------+-----------------------------------------------+ | Example | Output | +================================================+===============================================+ | :: | :: | | | | | {{ fn.object_keys input.object,true }} | ["boolean_1","boolean_3"] | | | | | | | | {{fn.object_keys input.object,"1"}} | ["string_1","string_1_dup"] | | | | | | | | | | | {{fn.object_keys input.object,1}} | ["integer_1","integer_1_dup"] | | | | | | | | | | | {{fn.object_keys input.object}} | ["boolean_1","boolean_2", | | | "boolean_3","string_1", | | | "string_1_dup","string_2", | | | "integer_1","integer_1_dup", | | | "integer_2"] | | | | +------------------------------------------------+-----------------------------------------------+ .. index:: Macro function;fn.object_empty * *fn.object_empty*: Returns and empty object Example: .. tabularcolumns:: |p{8cm}|p{7cm}| +--------------------------+--------+ | Example | Output | +==========================+========+ | :: | :: | | | | | {{ fn.object_empty }} | {} | | | | +--------------------------+--------+ .. index:: Macro function;fn.object_update * *fn.object_update* - Given an existing object and a key-value pair, updates and returns the given object with the key and value. * If the key dows not exist, the pair is added. * If the key exists, the value is updated. Examples: .. tabularcolumns:: |p{8cm}|p{7cm}| +------------------------------------------+------------------------------------+ | Example | Output | +==========================================+====================================+ | my_object: | | | | | | :: | | | | | | { "existing_key": "some_value" } | | | | | | function call: | | | | | | :: | :: | | | | | {{ fn.object_update "key","1234", | { "existing_key": "some_value", | | input.my_object }} | "key": "1234" } | | | | | | | +------------------------------------------+------------------------------------+ | my_object: | | | | | | :: | | | | | | { "key": "some_value" } | | | | | | function call: | | | | | | :: | :: | | | | | {{ fn.object_update "key","1234", | { "key": "1234" } | | input.my_object }} | | | | | | | | +------------------------------------------+------------------------------------+ .. index:: Macro function;fn.object_compare_specific * *fn.object_compare_specific*: This macro can for example be used to check previous and input context differences, providing a way to skip long updates on models if the comparison is true. .. note:: If we have fields that do not exist on the left or right side, these will be ignored/skipped and the result will be true. Given: * a list of fields we need to test for * a left object (dictionary) to compare against the right object * a right object (dictionary) that is compared with left object * a boolean flag: "true" to ignore nulls or blanks in the objects The flag defaults to False if any value other than 'true' is entered Return: A dictionary with the result of the comparison. If the comparison is false, return the Field the comparison failed on. Examples: Given the same example input below, the output of the two examples below is respectively ``"result": False`` or ``"result":True`` depending on the final input parameter: whether empty and blank fields should not or should be ignored. input: :: context = { "pwf": { "left_object": { "City": "Bellville", "FirstName": "Paul", "LastName": "Smith", "Department": None, "Age": "" }, "right_object": { "City": "Bellville", "FirstName": "Paul", "LastName": "Smith", "Department": None, "Age": "20" }, "field_list": [ "City", "FirstName", "LastName", "DoesNotExist", "Age", "Department" ] } } 1. command (don't ignore nulls or blanks): :: {{ fn.object_compare_specific pwf.field_list, pwf.left_object, pwf.right_object, false }} output: :: { "right_object": { "Department": None, "City": "Bellville", "Age": "20", "FirstName": "Paul", "LastName": "Kruger" }, "field_list_to_compare": [ "City", "FirstName", "LastName", "DoesNotExist", "Age", "Department" ], "ignore_null_and_blank": False, "left_object": { "Department": None, "City": "Bellville", "Age": "", "FirstName": "Paul", "LastName": "Kruger" }, "result": False, "field_match_results": [ { "field": "City", "left_value": "Bellville", "match": True, "right_value": "Bellville" }, { "field": "FirstName", "left_value": "Paul", "match": True, "right_value": "Paul" }, { "field": "LastName", "left_value": "Kruger", "match": True, "right_value": "Kruger" }, { "field": "DoesNotExist", "match": "Field not found, skip" }, { "field": "Age", "left_value": "", "match": False, "right_value": "20" }, { "field": "Department", "left_value": None, "match": True, "right_value": None } ] } 2. command (ignore nulls or blanks): :: {{ fn.object_compare_specific pwf.field_list, pwf.left_object, pwf.right_object, true }} output: :: { "right_object": { "Department": None, "City": "Bellville", "Age": "20", "FirstName": "Paul", "LastName": "Kruger" }, "field_list_to_compare": [ "City", "FirstName", "LastName", "DoesNotExist", "Age", "Department" ], "ignore_null_and_blank": True, "left_object": { "Department": None, "City": "Bellville", "Age": "", "FirstName": "Paul", "LastName": "Kruger" }, "result": True, "field_match_results": [ { "field": "City", "left_value": "Bellville", "match": True, "right_value": "Bellville" }, { "field": "FirstName", "left_value": "Paul", "match": True, "right_value": "Paul" }, { "field": "LastName", "left_value": "Kruger", "match": True, "right_value": "Kruger" }, { "field": "DoesNotExist", "match": "Field not found, skip" }, { "field": "Age", "match": "Field null or blank, skip" }, { "field": "Department", "match": "Field null or blank, skip" } ] } .. |VOSS Automate| replace:: VOSS Automate .. |Unified CM| replace:: Unified CM