Custom Button - IfElse Function

Custom Button - IfElse Function

We have a working custom function that can create PDFs from our module, in this instance we are using it to generate quotations from a lead module.

Button clicked > PDF created and attached to record

However, we operate in different countries and have different templates that change currency and date format.

So what I am trying to do is create an "IF ELSE" within the working function based on the selected currency of the lead.

E.g. If currency = USD excute this function A,  IF ELSE currency = GBP execute function B.
The intention to merge with the correct template based on currency.

Here is the function without currency if else.

templateid = "200903000003070203";
val = "Quotation for " + cname;
to_list = List();
from_map = Map();
to_map = Map();
mp = Map();
from_map.put("email",zoho.loginuserid);
from_map.put("user_name",zoho.loginuser);
to_map.put("email",email);
to_list.add(to_map);
mp.put("from_address",from_map);
mp.put("to_address",to_list);
mp.put("subject","Subject");
mp.put("content","Test Content");
mp.put("id",leadid);
mp.put("template_id",templateid);
// mp.put("attachment_name","Quotation for "+cname);
datalist = List();
datalist.add(mp);
datamap = Map();
datamap.put("data",datalist);
send = invokeurl
[
    url :"https://www.zohoapis.eu/crm/v2/Leads/actions/send_mail?type=mailmerge"
    type :POST
    parameters:datamap.tostring()
    connection:"zohocrm"
];
info "send:" + send;
file = invokeurl
[
    url :"https://zohoapis.eu/crm/v2/Leads/" + leadid + "/actions/print_preview?type=mailmerge&template_id=" + templateid + "&download_file_name=" + encodeUrl(val)
    type :GET
    connection:"zohocrm"
];
info file;
attach = zoho.crm.attachFile("Leads",leadid,file);
info attach;
return "Success! Refresh this page, PDF Proposal will appear in Attachments";


Additional considerations:

Macros and workflows will not work for this as you cannot trigger a macro from a custom button.
This feature MUST be controlled from a page view button, not a drop down menu.

    Access your files securely from anywhere








                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts



                                                            • Sticky Posts

                                                            • Function #46: Auto-Calculate Sales Margin on a Quote

                                                              Welcome back everyone! Last week's function was about displaying the discount amount in words. This week, it's going to be about automatically calculating the sales margin for a particular quote, sales order or an invoice. Business scenario Where there is sales, there's also evaluation and competition between sales reps. A healthy rivalry helps to better motivate your employees to do smart work and close deals faster and more efficiently. But how does a sales rep get evaluated? 90% of the time, it's
                                                            • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

                                                              Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
                                                            • User Tips: Auto-Create Opportunity/Deal upon Quote Save (PART 1)

                                                              Problem: We use quotes which convert to sales orders but Users / Sales Reps do not create opportunities / deals and go straight to creating a quote. This leads to poor reporting. Implementing this solution improves reporting and makes it easier for users.
                                                            • Custom Function : Automatically send the Quote to the related contact

                                                              Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
                                                            • Function #50: Schedule Calls to records

                                                              Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator 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


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ




                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方







                                                                                                              • Recent Topics

                                                                                                              • Zoho CRM Portal Field Level Permission Issue

                                                                                                                Hi Support Team, I am using the Zoho CRM Portal and configuring field-level editing permissions. However, we are unable to restrict portal users from editing certain fields. We have created a portal and provided View and Edit (Shared Only) access for
                                                                                                              • WebDAV / FTP / SFTP protocols for syncing

                                                                                                                I believe the Zoho for Desktop app is built using a proprietary protocol. For the growing number of people using services such as odrive to sync multiple accounts from various providers (Google, Dropbox, Box, OneDrive, etc.) it would be really helpful if you implemented standard protocols such as WebDAV / FTP / SFTP so that alternative inc clients can be used.
                                                                                                              • Different MRP / Pricing for same product but different batches

                                                                                                                We often face the following situations where MRP of a particular product changes on every purchase and hence we have to charge the customer accordingly. This can't be solved by Batch tracking as of now so far as I understand Zoho. How do you manage it as of now? 
                                                                                                              • 'Statement of Accounts does not exist' error received, when creating PO using api in Zoho Inventory

                                                                                                                Here is request json -- JSONString = { "date": "2019-09-24", "purchaseorder_number": "PO-6-1", "delivery_date": null, "delivery_org_address_id": 36221200000056XXX, "vendor_id": 362212000000564XXX, "attention": "Testing", "line_items": [{ "unit": "Pieces", "account_id": 36221200000003XXX, "quantity": 1, "item_id": 362212000000049XXX, "tax_type": "", "tax_name": "", "name": "One HD", "purchase_rate": 85, "tax_percentage": 0, "item_total": 85.00, "tax_id": "", "warehouse_id": 362212000000564XXX }] }
                                                                                                              • Zoho Projects API 100 requests/2 min. Limit

                                                                                                                Hi Requesting clarification on the API documentation. "You can invoke or call an API for 100 times in a span of two minutes. If you invoke more than 100 times, the particular API request will be locked for the next 30 minutes. " Does this limit apply
                                                                                                              • Unveiling Zoho Sites 2.0 - A new dimension in website building

                                                                                                                Dear Zoho Sites Users, We are thrilled to announce the launch of Zoho Sites 2.0 today! This refresh represents a significant step forward in the capabilities of Zoho Sites and is crucial for creating a lasting and positive impact on our customers' businesses.
                                                                                                              • Integrate your Outlook/ Office 365 inbox with Zoho CRM via Graph API

                                                                                                                Hello folks, In addition to the existing IMAP and POP options, you can now integrate your Outlook/Office 365 inbox with Zoho CRM via Graph API. Why did we add this option? Microsoft Graph API offers a single endpoint to access data from across Microsoft’s
                                                                                                              • PO Based Advance payment to Vendor

                                                                                                                We recommend to introduce a provision at PO to make advance payment to vendors and auto apply that advance paid later at the time of Vendor Bill submission for that PO. This will help us track PO-wise Total Payments.
                                                                                                              • Zoho Projects - Attachments added to Task and Bug emails are not saved

                                                                                                                Hi Projects team, I have been experimenting with emails into projects to create tasks and bugs. I have noticed that attachments added to the emails are not saved to the task or bug. Is this normal behaviour? Thanks, Ashley
                                                                                                              • Zoho Inventory's latest shipping integration updates at a glance.

                                                                                                                Hello Users, We would like to share some important news about our latest improvements in the Shipping integration capabilities of Zoho Inventory that we achieved in 2024 with some of our major integration partners in key editions across APAC, North America,
                                                                                                              • How we cut CRM updates from ~20 minutes down to 2, our real workflow

                                                                                                                Updating the Zoho CRM after every call used to be one of the biggest time sucks for our team. By the time you write your notes, clean them up, fill in the fields, and log everything properly… you’ve easily lost 15–20 minutes per call. We started experimenting
                                                                                                              • Identify long running sync jobs/tables

                                                                                                                My sync process causes strain on my production database and I'd love some tools/alerts to help me identify which tables are taking the longest. The current screen only shows 3 tables at a time and truncates the last fetch time so that it is very cumbersome
                                                                                                              • Sorting a list of record acquired from the zoho.crm.searchRecords function.

                                                                                                                This is something for which I'm trying to figure out a straightforward way to do. The searchRecords does a great job fetching me the records that I want. However, in some cases, where it returns multiple records, I want it to sort the returned list by date of creation of that record, so that when I do records.get(0), I get the most recent record.  As an example, here's my sample pseudo code: records = zoho.crm.searchRecords("Clients", "Office_Number:equals:123456"); Now the "records" list above contains
                                                                                                              • Zoho Inventory Custom Field Update

                                                                                                                Hello All, In this post I am describing how can we Update the Custom Field Value in Zoho Inventory. // Get Org ID orgid = organization.get("organization_id"); // Field Value resvp = ifnull(item.get("purchase_rate"),null); // Record ID iid = item.get("item_id");
                                                                                                              • Deprecation of the Zoho OAuth connector

                                                                                                                Hello everyone, At Zoho, we continuously evaluate our integrations to ensure they meet the highest standards of security, reliability, and compliance. As part of these ongoing efforts, we've made the decision to deprecate the Zoho OAuth default connector
                                                                                                              • Alphabetically

                                                                                                                How can i arrange alphabetically - (Manage Manufacturer) Field in Item Master 
                                                                                                              • Spotlight series #6: The Show app for Android TV has a new look!

                                                                                                                Hello everyone! We are delighted to introduce our revamped and redesigned Show app for Android TV.  Smart TVs are exploding in popularity. Android TV alone has over 110 million active monthly devices. Zoho Show, as part of a constant effort to improve
                                                                                                              • Can i set a default value for country and state in address field in zoho creator?

                                                                                                                Can i set a default value for country and state in address field in zoho creator?
                                                                                                              • Using gift vouchers

                                                                                                                We would like to be able to offer a limited number of gift vouchers, of varying values, to our customers, and are looking for the best way to do this. We have looked at Coupons and Gift Certificates, but neither seem to fit the bill perfectly. Coupons:
                                                                                                              • Convert HTML to PDF & Send as Email Attachments in Zoho Creator (Deluge)

                                                                                                                This approach is useful for sending welcome letters, instructions, or promotional offers after order creation. // 1. Define the variables using the submitted input customerName = input.Customer_Name1; orderID = input.ID; customerEmail = input.Email_Address; //
                                                                                                              • Redirect after submission is not working after a few submission

                                                                                                                I have setup redirect url correctly and everything works as expected. However, it seems that there's a limit to the number of submissions before the redirect stops working. After the "limit" is reached, the page redirects to a seemingly zoho hosted page,
                                                                                                              • Enhancement Request for Multi-Asset Work Order Feature

                                                                                                                Hello Latha, Thank you for your continued support. The multi-asset Work Order feature is extremely helpful. I did some testing based on our requirements, and during the process, I noticed a few areas where we need your team’s support to improve the feature
                                                                                                              • Marketing Tip #8: Run limited-time offers

                                                                                                                Exclusive offers that don't last long make shoppers purchase right away instead of waiting. Run a flash sale or limited-time discount to convert interest into sales. Try this today: Set up a "Buy X Get Y" coupon in Zoho Commerce valid for a limited time
                                                                                                              • Add Option to Mass Dispatch by User

                                                                                                                Hello! We are using the dispatch console to dispatch service appointments to our service ressources. Right now, the process is our dispatcher verifies each ressource's route for the day and dispatches it after validation. Sadly, there doesn't seem to
                                                                                                              • Free webinar: Zoho Sign unwrapped – 2025 in review

                                                                                                                Hey there! 2025 is coming to an end, and this year has been all about AI. Join our exclusive year-end webinar, where we'll walk you through the features that went live in 2025, provide answers to your questions, and give you a sneak peek on what to expect
                                                                                                              • Zoho Projects - Email notification relabelling of modules not present on default templates

                                                                                                                Hi Projects Team, I noticed that in the default email template notification, the word "bug" was not renamed to the lable I am using in my system. As many users may used the Bugs modules for various purposes including Changes, Revisions, Issues, etc...
                                                                                                              • Publish to LinkedIn via API

                                                                                                                Hi, Is it possible to publish a job opening to LinkedIn (paid job slots) if creating a job opening via api / deluge function? Or is the user required to manually publish via the job boards process? Many Thanks Adrian
                                                                                                              • Is there a way to automatically add Secondary Contacts (CCs) when creating a new ticket for specific customers?

                                                                                                                Some of our customers want multiple contacts to receive all notifications from our support team. Is there a way to automatically add secondary contacts to a ticket when our support team opens a new ticket and associates it with an account? This would
                                                                                                              • Include the "Added Email ID" to the Filters of a Report

                                                                                                                Hi, With a Report and lots of entries, a normal thing is to filter entries by the submitter, but that is not included in the Auto Filter of Reports and you can't add a custom filter to a Report without specifying the actual value. I would like to be able
                                                                                                              • Loops in Deluge

                                                                                                                Hi, Can someone tell me how I do a simple loop in deluge? For example, if i have a variable "X" containing a number of loops to perform, i would like to perform an action X amount of times. X = 10; do while (Y < X){       // ... do something } to further explain, the equivalent in PHP of what i am trying to acheive would be: $X = 20; for($Y = 1; $Y < $X; $Y++ ){       // ... do something } Thanks
                                                                                                              • I am facing a problem with an if-else condition

                                                                                                                If I use if, else if, and else conditions in Deluge with the same variable name, sometimes the variable causes an error because the same variable name is present in every block
                                                                                                              • Zoho Projects - Reply by email to @ mentions posted on the Feed.

                                                                                                                When mentioning someone on the Feed (Status), it would be great if that mentioned person could reply to the email notification to update the Feed thread.
                                                                                                              • Add home page or dashboard in CRM customer portal

                                                                                                                is it possible to add home page or dashboard in CRM customer portal?
                                                                                                              • Zoho Analytics Bulk Api Import json Data

                                                                                                                HI, I’m trying to bulk-update rows in Zoho Analytics, and below are the request and response details. I’d like to understand the required parameters for constructing a bulk API request to import or update data in a table using Deluge. Any guidance on
                                                                                                              • Product Updates in Zoho Workplace applications | October 2025

                                                                                                                Hello Workplace Community, Let’s take a look at the new features and enhancements that went live across all Workplace applications this October. Zoho Mail Create Signature from Compose window You can now effortlessly create a Signature using the Create
                                                                                                              • Subform data to Sheets

                                                                                                                I have been trying to setup a Zoho Flow automation to bring any Subform input to a Zoho Sheets but it seems impossible to post the subform entries to a Zoho Sheet. Is there any way to do it via Zoho Sheet API? https://www.zoho.com/sheet/help/api/v2/#CONTENT-Insert-row-with-JSON-data
                                                                                                              • E-Invoicing in Belgium with Zoho Books

                                                                                                                Starting January 1, 2026, Belgium is introducing mandatory electronic invoices (e-invoicing) for all B2B transactions between VAT-registered businesses. This means that invoices and credits notes must be exchanged in a prescribed digital format. How E-Invoicing
                                                                                                              • Edit Contact Roles in the Potentials Mod

                                                                                                                New to ZOHO so I need some help. I work the same people on different projects concurrency. Their contact info remains the same but their role changes from project to project. In the Potential Mod you can pick contacts and assign a Role to them. I know
                                                                                                              • Is there a way to disable the Activity Reminders Pop-Up Window every time I log in?

                                                                                                                Just wondering if there is a setting to disable the window from opening every time I open my CRM? Thanks Chris
                                                                                                              • Auto-sync field of lookup value

                                                                                                                This feature has been requested many times in the discussion Field of Lookup Announcement and this post aims to track it separately. At the moment the value of a 'field of lookup' is a snapshot but once the parent lookup field is updated the values diverge.
                                                                                                              • Next Page