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

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.