How to merge subform fields and image field with Zoho Writer's Merge APIs in Zoho CRM

How to merge subform fields and image field with Zoho Writer's Merge APIs in Zoho CRM

How to merge subform fields via Merge API's in Zoho Writer

Sample Merge Template consisting of both Normal and RL fields:
Quote

Hello <<Contacts.First Name>>
Send a mail to <<Contacts.Email>>

Invoice Owner
Invoice Number
Created By
Due Date
<<Invoices.Invoice Owner>>
<<Invoices.Invoice Number>>
<< Invoices. Created By>>
<<Invoices.Due Date>>

Product_Code

Product_Description

Item_Quantity

Item_Price

 

«Products.Product_Code»

 

«Products.Product_Description»

 

«Products.Item_Quantity»

 

«Products.Item_Price»


2. Sample code to get the RL fields info

fields = invokeurl
[
type: GET
connection:"writercrm"
];
info fields;
Notes

document_id
 -> It can be derived from the document open url: https://{{domain}}/writer/open/eb4kob4cf65bb6d074af****************
Ex: document_id="eb4kob4cf65bb6d074af****************"

connection_name -> Please refer this link to know more about Connection in Deluge and how to create it. 
Ex: connection_name="writer_name" 

Sample response of Step 2:
Quote

 

{

  "merge": [

    {

      "id": "First_Name",

      "groupname": "Contacts",

      "display_name": "First Name",

      "type": "text"

    },

    {

      "id": "Email",

      "groupname": "Contacts",

      "display_name": "Email",

      "type": "email"

    },

    {

      "id": "Invoices",

      "display_name": "Invoices",

      "type": "subform",

      "fields": [

        {

          "id": "Invoices.Owner",

          "groupname": "Invoices",

          "display_name": "Invoice Owner",

          "type": "text"

        },

        {

          "id": "Invoices.Invoice_Number",

          "groupname": "Invoices",

          "display_name": "Invoice Number",

          "type": "number"

        },

        {

          "id": "Invoices.Created_By",

          "groupname": "Invoices",

          "display_name": "Created By",

          "type": "text"

        },

        {

          "id": "Invoices.Due_Date",

          "groupname": "Invoices",

          "display_name": "Due Date",

          "type": "text"

        }

      ]

    },

    {

      "id": "Products",

      "display_name": "Products",

      "type": "subform",

      "fields": [

        {

          "id": "Products.Product_Code",

          "groupname": "Products",

          "display_name": "Product Code",

          "type": "text"

        },

        {

          "id": "Products.Product_Description",

          "groupname": "Products",

          "display_name": "Product Description",

          "type": "text"

        },

        {

          "id": "Products.Item_Quantity",

          "groupname": "Products",

          "display_name": "Item Quantity",

          "type": "number"

        },

        {

          "id": "Products.Item_Price",

          "groupname": "Products",

          "display_name": "Item Price",

          "type": "number"

        }

      ]

    }

  ],

  "sign": {},

  "fill": {}

}

3. Sample code to map the RL fields (via deluge)

Quote

invoicesRecords = zoho.crm.getRecordById("Invoices", invoiceId);

 

CustomerInvoice = Map();

CustomerInvoice.put("First_Name", invoicesRecords.get("Account_Name").get("name"));

CustomerInvoice.put("Email", invoicesRecords.get("Account_Name").get("id"));

 

invoicesList = list();

invoiceDetails = Map();

 

invoiceDetails.put("Invoices.Owner", invoicesRecords.get("Owner").get("name"));

invoiceDetails.put("Invoices.Invoice_Number", invoicesRecords.get("Invoice_Number"));

invoiceDetails.put("Invoices.Created_By", invoicesRecords.get("Created_By").get("name"));

invoiceDetails.put("Invoices.Due_Date", invoicesRecords.get("Due_Date"));

invoicesList.add(invoiceDetails);

 

productList = list();

productDetails = Map();

productDetails.put("Products.Product_Code", invoicesRecords.get("Product_Code"));

productDetails.put("Products.Product_Description", invoicesRecords.get("Product_Description"));

productDetails.put("Products.Item_Quantity", invoicesRecords.get("Item_Quantity"));

productDetails.put("Products.Item_Price", invoicesRecords.get("Item_Price"));

productList.add(productDetails);

 

 

CustomerInvoice.put("Invoices", invoicesList);

CustomerInvoice.put("Products", productList)

 

 

mergedata = Map();

mergedata.put("merge_data", {"data": CustomerInvoice});

mergedata.put("subject", "Invoice Details");

 

//optional

mergedata.put("message", "Please find your invoice attached.");

info mergedata;

 

zoho.writer.mergeAndSend("eb4kob4cf65bb6d074af7a7de21e561119eb9", "pdf", invoicesRecords.get("email"), mergedata, "writer_name");

4. Sample JSON data with RL fields (via APIs)

Quote

{

    "data": [

        {

            "First_Name": "Amelia",

            "Email": "amelia@zylker.com",

            "Invoices": [

                {

                    "Invoices.Owner": "John",

                    "Invoices.Invoice_Number": 1279,

                    "Invoices.Created_By": "Amelia",

                    "Invoices.Due_Date": "07/10/2020"

                }

            ]

            "Products": [

              {

                "Products.Product_Code": "A123",

                "Products.Product_Description": "Mobile Cases",

                "Products.Item_Quantity": 2,

                "Products.Item_Price": 1000

              }

            ]

        }

    ]


Notes
To know how to pass the values for all the available merge field types, please refer this link.

How to pass image fields values to Zoho CRM's mail merge via API

When conducting a mail merge from Zoho CRM using our Merge APIs, if the merge template includes image fields, you'll need to construct the value for those image fields on your end. Zoho CRM will solely provide the Preview Image ID value for the image field, rather than the complete preview Image URL.

Please follow the below steps to construct the Image URL to pass as image field value;

1. Invoke Get Record API (version 5 and above) and get the Preview Image ID [Preview_Id__s] of that image field from the response. Using this Preview Image ID, you need to construct the image url as mentioned below.

Sample values to replace the variables in the snippet shared below:
Info
Module = "Leads";   //Provide your respective module name
RecordId = "456789";   //CRM record id
RLModuleName = "Products";   //Related List Name
zohoapi_domain (for US DC) = "https://www.zohoapis.com";   //For other DCs, refer the API domains here.
Sample Snippet:
Quote

// get Records
recordInfo = invokeurl
[
url :zohoapi_domain+"/crm/v5/"+Module+"/"+RecordId;
type :GET
connection:"crm"
];
recordInfoData = recordInfo.get("data").get(0);
dataMap = Map();
dataMap.put("Email",recordInfoData.get("Email"));
dataMap.put("Last_Name",recordInfoData.get("Last_Name"));
// Image field
if(recordInfoData.get("Image_Upload") != null)
{
imageId = recordInfoData.get("Image_Upload").get(0).get("Preview_Id__s");
imageUrl = zohoapi_domain+"/crm/v2.1/__attachment_preview/" + imageId;    //constructed image url 
dataMap.put("Image_Upload",imageUrl);
}
info dataMap;

2. If image field is a RL record, then invoke this Related Records Data API (version 5 and above) to get the RL Record ID. Then, invoke the Get Records API with this RL Record ID to get the Preview Image ID.

Sample Snippet:
Quote

dataMap = Map();
 //Get Related List IDs
relatedListsIds = invokeurl
[
url:zohoapi_domain+"/crm/v5/"+Module+"/"+RecordId+"/"+RLModuleName+"?fields=Parent_Id"
type :GET
connection:"crm"
];
rlListData = relatedListsIds.get("data");
rlProductsList = List();
//Get Related List Data
for each  record in rlListData
{
rlId = record.getJSON("id");
rlInfo = invokeurl
[
url :zohoapi_domain+"/crm/v5/+"RLModuleName+"/" + rlId
type :GET
connection:"crm"
];
rlInfoData = rlInfo.get("data").get(0);
rlMap = Map();
rlMap.put("Product_Name",rlInfoData.getJSON("Product_Name"));
rlMap.put("Product_Code",rlInfoData.getJSON("Product_Code"));
//RL Image Field
if(rlInfoData.get("Image_Upload") != null)
{
rlImageId = rlInfoData.get("Image_Upload").get(0).get("Preview_Id__s");
imageUrl = zohoapi_domain+"/crm/v2.1/__attachment_preview/" + rlImageId;  //constructed image url
rlMap.put("Image_Upload",imageUrl);
}
rlProductsList.add(rlMap);
}
//Add Related List to dataMap
dataMap.put("Products",rlProductsList);
info dataMap;


    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION





                          Quick Links Workflow Automation Data Collection
                          Web Forms Enterprise Begin Data Collection
                          Interactive Forms Workplace Data Collection App
                          CRM Forms Customer Service Accessible Forms
                          Digital Forms Marketing Forms for Small Business
                          HTML Forms Education Forms for Enterprise
                          Contact Forms E-commerce Forms for any business
                          Lead Generation Forms Healthcare Forms for Startups
                          Wordpress Forms Customer onboarding Order Forms for Small Business
                          No Code Forms Construction RSVP tool for holidays
                          Free Forms Travel
                          Prefill Forms Non-Profit

                          Intake Forms Legal
                          Mobile App
                          Form Designer HR
                          Mobile Forms
                          Card Forms Food Offline Forms
                          Assign Forms Photography
                          Mobile Forms Features
                          Translate Forms Real Estate Kiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives Security & Compliance
                          Holiday Forms Google Forms alternative  GDPR
                          Form to PDF Jotform alternative HIPAA Forms
                          Email Forms
                          Encrypted Forms
                          Embeddable Forms
                          Secure Forms
                          Drag and Drop form builder
                          WCAG


                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • How to merge Subform Fields via Merge API's in Writer?

                                                                                                                1. Create a Merge template in Writer with related (RL) fields Sample Merge Template consisting of both Normal and RL fields: Hello <<Contacts.First Name>> Send a mail to <<Contacts.Email>> Invoice Owner Invoice Number Created By Due Date ...
                                                                                                              • How to use Zoho WorkDrive images into Writer merge fields?

                                                                                                                Zoho Writer only accepts Public URL for the image fields in Mail merge. If the images are stored in Zoho WorkDrive, you can create a downloadable link and use it as an input value for the image field. This can be done in the following three ways; a) ...
                                                                                                              • Working with Fields

                                                                                                                Supported field types Supported field types Description Possible Values in the data source Rendered as Notes Plain Text The value of the field is placed as a string in the document. “test” “test” You can select the field in the document and apply the ...
                                                                                                              • Mail merge support for Zoho CRM modules

                                                                                                                What are the CRM modules that are supported for mail merge with Zoho Writer? With the Zoho Writer Add-on, you can create mail merge documents using CRM data from the following modules: Leads Accounts Contacts Deals Quotes Sales Orders Invoices ...
                                                                                                              • How to merge Writer templates using Zoho Flow?

                                                                                                                We're working on a Zoho Flow-Writer integration to help you pick template documents from Writer, place merge fields on them and merge it with data from Zoho Services. Find below steps to merge Writer Documents and with Zoho Creator Form fields. Steps ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources