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.