Writer merge and store API - data from multiple modules

Hi, we’ve been able to merge and store a mail merge doc over Writer’s api.  The following code snippet worked for merging on templates that consumed data from only one module:

 

module1_data = zoho.crm.getRecordById("Module1",3776515000555555555);

param = Map();

param.put("merge_data",{"data":module1_data});

 

url = https://www.zohoapis.com/writer/api/v2/documents/ + resource_id + "/merge/store";

merge_result = invokeurl

[

               url :url

               type :POST

               parameters:param

               connection:"writer"

];

 

The code above worked great as we could just put the entire module record in the ‘param’ map instead of defining individual variables for each merge doc field.   However, we have a new use case where a merge doc uses fields from 3 distinct CRM modules and I’m not sure how I could put the records from all 3 modules into the ‘param’ map.    

 

I think I could create a fields map and individually map all the necessary fields but I’d really like to avoid this, especially since our merge docs are occasionally updated to consume different fields.  I’d prefer not to have to update the function when a merge template is updated. 

 

With that in mind, is there a way to combine the 3 module records into one new variable (not sure if this would be a Map or List or something else) and then put that new variable in the param map/variable that I’m already using?   I’ve tried to do this on my own but couldn’t seem to figure it out.   I know the following probably isn’t even close to correct, but it kind of demonstrates what I’m wondering is possible:

 

module1_data = zoho.crm.getRecordById("Module1",3556515000111111111);

module2_data = zoho.crm.getRecordById("Module2",3556515000222222222);

module3_data = zoho.crm.getRecordById("Module3",3556515000333333333);

 

new_variable = Map();

put.new_variable(“data1”,module1_data);

put.new_variable(“data2”module2_data);

put.new_variable(“data3”module3_data);

 

param = Map();

param.put("merge_data",{"data":new_variable});

 

Any chance this is possible and if so can someone suggest how to write?

 

Thanks!