Zoho CRM and Zoho Writer Merge and Send Function - Not Merging

Zoho CRM and Zoho Writer Merge and Send Function - Not Merging

Overall Problem
I needed a solution to automatically calculate and send employee payslip information stored on Zoho CRM, to each of our employees at the end of each month based on their salary, allowances and sales commissions (sales commissions - which may change each pay period based on deals completed)

Solution
I create a module on Zoho CRM called "Payslip Records", which contains records for each employee with their personal information, total sales commissions, allowances, net salary etc.

I then created a payslip template in Zoho Writer, and used the merge fields from the CRM "Payslips Module" to populate the fields on the payslip in Zoho Writer. If I run this manually from Zoho CRM, it works - the fields are merged and I can send the payslip to the employees via email.

Automating Challenge - Merge and Send Function in Zoho CRM not Merging Fields
So that the process could be automated with a workflow, I created a function which seems to be working - teh console log returns successful. However, when the function runs and the email is sent off I receive blank payslip templates in my inbox. Here's a look at my code below, can anyone explain why this might be happening that's wrong?

  1. payslipRecords = zoho.crm.getRecordById("Payslip_Records",payslipId,"crmwriter");
  2. fields = zoho.writer.getMergeFields("cpqhxd8f21b4c97794e3089ed074e21b45a51","crmwriter");
  3. info "fields : " + fields;
  4. info "payslipRecords : " + payslipRecords;
  5. data = Map();
  6. //data.put("First_Name", payslipRecords.get("Account_Name").get("name"));
  7. //data.put("Email", payslipRecords.get("Account_Name").get("id"));
  8. payslips = list();
  9. payslipfield = Map();
  10. payslipfield.put("Payslip_Records. Employee Name",ifnull(payslipRecords.get("Name"),""));
  11. payslipfield.put("Payslip Records. Department",ifnull(payslipRecords.get("Department"),""));
  12. payslipfield.put("Payslip Records. Pay Period",ifnull(payslipRecords.get("Pay_Period"),""));
  13. payslipfield.put("Payslip Records. Date of Payment",ifnull(payslipRecords.get("Date_of_Payment"),""));
  14. payslipfield.put("Payslip Records. Salary",ifnull(payslipRecords.get("Salary"),""));
  15. payslipfield.put("Payslip Records. Upfront Commissions",ifnull(payslipRecords.get("Upfront_Commissions"),""));
  16. payslipfield.put("Payslip Records. Recurring Commissions",ifnull(payslipRecords.get("Recurring_Commissions"),""));
  17. payslipfield.put("Payslip Records. Internet",ifnull(payslipRecords.get("Internet"),""));
  18. payslipfield.put("Payslip Records. Net Pay",ifnull(payslipRecords.get("Net_Pay"),""));
  19. payslips.add(payslipfield);
  20. data.put("Payslip_Records",payslips);
  21. mergedata = Map();
  22. mergedata.put("merge_data",{"data":data});
  23. mergedata.put("subject","Payslip Due");
  24. //optionalDF
  25. mergedata.put("message","Please find your payslip attached.");
  26. info "mergedata : " + mergedata;
  27. update = zoho.writer.mergeAndSend("cpqhxd8f21b4c97794e3089ed074e21b45a51","pdf",payslipRecords.get("Email"),mergedata,"crmwriter");
  28. info "update : " + update;

Console Information
  1. Info
    • fields : {"rl_fields":[],"fields":["Employee_Name"]}
    • payslipRecords : {"Salary":1000,"Owner":{"name":"John Doe","id":"4035844000008772172","email":"john@email.com"},"Email":"john@email.com","$currency_symbol":"Bds$","Net_Pay":1260.45,"$review_process":{"approve":false,"reject":false,"resubmit":false},"Name":"John Doe","Last_Activity_Time":null,"Record_Image":null,"Modified_By":{"name":"John Doe","id":"4035844000008772172","email":"john@email.com"},"Department":"Operations","$review":null,"$state":"save","Unsubscribed_Mode":null,"$process_flow":false,"Exchange_Rate":1,"Currency":"BBD","id":"4035844000024583003","$approved":true,"Recurring_Commissions":10.45,"$approval":{"delegate":false,"approve":false,"reject":false,"resubmit":false},"Modified_Time":"2021-02-23T10:20:21-04:00","Created_Time":"2021-02-23T10:20:21-04:00","Unsubscribed_Time":null,"$editable":true,"Date_of_Payment":"2021-02-28","$orchestration":false,"$in_merge":false,"Tag":[],"Internet":50,"Upfront_Commissions":200,"$approval_state":"approved","Pay_Period":"2021-02-15"}
    • mergedata : {"merge_data":{"data":{"Payslip_Records":[{"Payslip_Records. Employee Name":"John Doe","Payslip Records. Department":"Operations","Payslip Records. Pay Period":"2021-02-15","Payslip Records. Date of Payment":"2021-02-28","Payslip Records. Salary":1000,"Payslip Records. Upfront Commissions":200,"Payslip Records. Recurring Commissions":10.45,"Payslip Records. Internet":50,"Payslip Records. Net Pay":1260.45}]}},"subject":"Payslip Due","message":"Please find your payslip attached."}
    • update : {"merge_report_data_url":"https://docs.zoho.com/writer/api/v1/merge/job/aa5fea7ce716f6854f78ce450bf8333c67f0dd47c7f5a6b3f6fe5644fe18afcc/data","merge_report_url":"https://docs.zoho.com/writer/v1/mailmerge/job/aa5fea7ce716f6854f78ce450bf8333c67f0dd47c7f5a6b3f6fe5644fe18afcc","records":[{"download_link":"https://docs.zoho.com/writer/api/v1/merge/job/aa5fea7ce716f6854f78ce450bf8333c67f0dd47c7f5a6b3f6fe5644fe18afcc/record/aa5fea7ce716f6854f78ce450bf8333c9587b8912fcf060c77d27971ad2eecd9/attachment/1/download","SEQUENCE":1,"Payslip_Records":[{"Payslip Records. Net Pay":1260.45,"Payslip Records. Recurring Commissions":10.45,"Payslip Records. Department":"Operations","Payslip_Records. Employee Name":"John Doe","Payslip Records. Internet":50,"Payslip Records. Pay Period":"2021-02-15","Payslip Records. Date of Payment":"2021-02-28","Payslip Records. Upfront Commissions":200,"Payslip Records. Salary":1000}],"id":"758541b4-e20f-4275-a434-fe32553c3b65","status":"inprogress"}]}
    Function executed successfully

Please help if you can, thanks! I've attached images of the merge template with the field ID's in Zoho Writer for reference.


    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Deprecation of certain URL patterns for published Zoho Writer documents

                                                Hi Zoho Writer users! We'd like to let you know that we have deprecated certain URL patterns for published and embedded documents in Zoho Writer due to security reasons. If the published or embedded documents are in any of these URL patterns, then their
                                              • [Announcement] Insert image from URL changes in Zoho Writer

                                                Hi Zoho Writer users! We'd like to let you know that we've changed the behavior of the Insert image from URL option in Zoho Writer for security reasons. Earlier behavior Once you inserted an image URL in a Writer document, the image would be fetched from
                                              • Introducing plagiarism checker in Zoho Writer

                                                Zia, Zoho Writer's AI-driven writing assistant, now highlights plagiarized and duplicated content in addition to offering contextual grammar and writing suggestions to help you write clearly and concisely in English. Zoho Writer's plagiarism reports Here
                                              • [Important announcement] Impact of Google's new email guidelines for Zoho Writer automation users

                                                Hi users, Google has recently announced new guidelines for sending emails to Gmail and other Google-hosted domains. These guidelines will be effective starting Feb. 1, 2024, and can impact the delivery of emails sent from Zoho Writer. Your organization
                                              • Transitioning from MS Word to Writer: A complete walkthrough

                                                Hello everyone! We understand moving to a new word processing tool can be difficult, especially if it means switching from a legacy software like MS Word. That's why we've organized an exclusive webinar where we talk you through ways to make your switch from MS Word to Writer as easy as possible. In this webinar, you'll learn: - Why Writer is a simple yet powerful alternative to MS Word. - How to locate your favorite MS Word features and functions in Writer.  - How to migrate your Word documents


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now