How to pass Dict/JSON like object to macross from iframe

hi, I wrote a macro that replaces value of userfields, it works but only with text (str), when i try send array (dict in python) to macros i got NoneType error for object1 array.

            function CheckDictPass() {
            const object1 = {"FIO": 1, "FIO2": 2, "FIO22": 3};
            
            window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*')
            window.frames[0].postMessage(JSON.stringify({
                        'MessageId': 'CallPythonScript',
                        'SendTime': Date.now(),
                        'ScriptFile': 'replace_userfield.py',
                        'Function': 'replace_userfield3',
                        'Values': {

                            - works
                            'userfield_name': {'type': 'string', 'value': userfield_name},
                            'userfield_value': {'type': 'string', 'value': userfield_value},
                            
                             - don't work NoneType error
                            'dataset': {'type': 'object', 'value': object1},

                        }

                    }),
                    '*')

Hi @kireev20000, welcome to the Collabora Online forum!

You don’t need to specify the type as object. Instead, you can directly pass the dictionary object. Here’s how to rephrase your answer:

window.frames[0].postMessage(JSON.stringify({
    'MessageId': 'CallPythonScript',
    'SendTime': Date.now(),
    'ScriptFile': 'replace_userfield.py',
    'Function': 'replace_userfield3',
    'Values': {
        'userfield_name': {'type': 'string', 'value': userfield_name},
        'userfield_value': {'type': 'string', 'value': userfield_value},
        'dataset': object1, // Directly passing the dictionary
    }
}), '*');

Example of how to pass values:

post({
    'MessageId': 'CallPythonScript',
    'SendTime': Date.now(),
    'ScriptFile': 'NamedRanges.py',
    'Function': 'DefineNamedRange',
    'Values': {
        'sheet': {'type': 'string', 'value': 'Sheet1'},
        'x0': {'type': 'long', 'value': x0},
        'y0': {'type': 'long', 'value': y0 - 1},
        'width': {'type': 'long', 'value': x1 - x0 + 1},
        'height': {'type': 'long', 'value': y1 - y0 + 1},
        'name': {'type': 'string', 'value': name}
    }
});

This method allows you to pass a dictionary object directly to your Python macro without needing to specify the type as object. The example demonstrates how to pass various types of values, ensuring your data is correctly handled on both the JavaScript and Python sides.