Function - Examples
Functions help you update data in related CRM modules or third-party applications by executing simple program scripts. With Functions, you can program scripts using Deluge Script (powered by Zoho Creator), associate them to workflow rules, and automate the business process. Some of the most useful Functions are listed below.
Button-type Functions
Convert leads into records in other modules.
Function type: Button
Function description: You can convert leads into records of other modules such as Accounts, Contacts, Potentials, etc, with just the click of a button.
How to get it to work:
Button placement: The button must be placed in the View page of the Leads module.
Argument mapping: To configure this action,- Click Setup > Customization > Modules > Leads > Links and Buttons > +Create new button.
- Enter the button name > Choose view page > Choose Writing Functions.
- Enter the name of the Function and click on Free flow scripting.
- Copy the code given below.
- Click Edit arguments.
- Enter the name as 'leadId' and choose the value as 'Lead ID'.
- Click +Add argument and type the name as "Authtoken".
- Click "Specify custom value" and enter the CRM Authtoken in the box.
- Click Done.
- Check the code script and click Save.
- In the Create your button page, click Save.
Note
If you don't want to delete the lead record after it has been converted, please comment the last line of the script.
Script:
leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads", leadIdLong);
first = ifnull(leadDetails.get("First Name"),"");
last = ifnull(leadDetails.get("Last Name"),"");
name = first + " " + last;
AcccountMap = map();
AcccountMap.put(("Account Name"), ifnull(leadDetails.get("Company"),""));
AcccountMap.put("Annual Revenue", ifnull(leadDetails.get("Annual Revenue"),""));
AcccountMap.put("Billing City", ifnull(leadDetails.get("City"),""));
AcccountMap.put("Billing Country", ifnull(leadDetails.get("Country"),""));
AcccountMap.put("Description", ifnull(leadDetails.get("Description"),""));
AcccountMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
AcccountMap.put("Industry", ifnull(leadDetails.get("Industry"),""));
AcccountMap.put("Employees", ifnull(leadDetails.get("No of Employees"),""));
AcccountMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
AcccountMap.put("Rating", ifnull(leadDetails.get("Rating"),""));
AcccountMap.put("Billing State", ifnull(leadDetails.get("State"),""));
AcccountMap.put("Billing Street", ifnull(leadDetails.get("Street"),""));
AcccountMap.put("Billing Code", ifnull(leadDetails.get("Zip Code"),""));
AcccountMap.put("Website", ifnull(leadDetails.get("Website"),""));
AccountCreate = zoho.crm.create(("Accounts"), AcccountMap);
newaccountId = AccountCreate.get("Id");
ContactMap = map();
ContactMap.put("First Name", ifnull(leadDetails.get("First Name"),""));
ContactMap.put("Last Name", ifnull(leadDetails.get("Last Name"),""));
ContactMap.put("Mailing City", ifnull(leadDetails.get("City"),""));
ContactMap.put("Mailing Country", ifnull(leadDetails.get("Country"),""));
ContactMap.put("Mailing State", ifnull(leadDetails.get("State"),""));
ContactMap.put("Mailing Street", ifnull(leadDetails.get("Street"),""));
ContactMap.put("Mailing Zip", ifnull(leadDetails.get("Zip Code"),""));
ContactMap.put("Description", ifnull(leadDetails.get("Description"),""));
ContactMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
ContactMap.put("Title", ifnull(leadDetails.get("Title"),""));
ContactMap.put("Email", ifnull(leadDetails.get("Email"),""));
ContactMap.put("Lead Source", ifnull(leadDetails.get("Lead Source"),""));
ContactMap.put("Mobile", ifnull(leadDetails.get("Mobile"),""));
ContactMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
ContactMap.put("Secondary Email", ifnull(leadDetails.get("Secondary Email"),""));
ContactMap.put("Skype ID", ifnull(leadDetails.get("Skype ID"),""));
ContactMap.put("Twitter", ifnull(leadDetails.get("Twitter"),""));
ContactMap.put("ACCOUNTID", newaccountId);
ContactCreate = zoho.crm.create("Contacts", ContactMap);
newcontactId = ContactCreate.get("Id");
PotentialMap = map();
PotentialMap.put("Potential Name", name);
PotentialMap.put("City", ifnull(leadDetails.get("City"),""));
PotentialMap.put("Country", ifnull(leadDetails.get("Country"),""));
PotentialMap.put("State", ifnull(leadDetails.get("State"),""));
PotentialMap.put("Street", ifnull(leadDetails.get("Street"),""));
PotentialMap.put("Zipcode", ifnull(leadDetails.get("Zip Code"),""));
PotentialMap.put("Description", ifnull(leadDetails.get("Description"),""));
PotentialMap.put("Lead Source", ifnull(leadDetails.get("Lead Source"),""));
PotentialMap.put("ACCOUNTID",newaccountId );
PotentialMap.put("CONTACTID",newcontactId );
PotentialCreate = zoho.crm.create("Potentials", PotentialMap);
url = getUrl("https://crm.zoho.com/crm/private/xml/Leads/deleteRecords?authtoken=" + input.Authtoken + "&scope=crmapi&id=" + input.leadId);
return "Lead converted successfully";Create Invoices from Purchase orders.
Function type: Button
Function description: Generate an Invoice for a purchase order with just the touch of a button. As simple as that.
How to get it to work:
Button placement: This button must be places in the View page of Purchase Order module.
Argument mapping: To configure this action,- Click Setup > Customization > Modules > Purchase Orders > Links and Buttons > +Create new button.
- Enter the button name > Choose view page > Choose Writing Functions.
- Enter the name of the Function and click on Free flow scripting.
- Copy the code given below.
- Click Edit arguments.
- Enter the name as 'poId' and choose the value as 'Purchase Order ID'.
- Click Done.
- Check the code script and click Save.
- In the Create your button page, click Save.
Script:
respMap = zoho.crm.getRecordById("PurchaseOrders", input.poId.toLong());
productDet = ifnull(respMap.get("product"),"");
productList = productDet.toJSONList();
pdlist = List();
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
productDesc = ifnull(eachProdDet.get("Product Description"),"");
quantity = ifnull(eachProdDet.get("Quantity"),"0");
listPrice = (ifnull(eachProdDet.get("List Price"),"0.0")).toDecimal();
netTotal = (ifnull(eachProdDet.get("Net Total"),"0.0")).toDecimal();
linediscount = (ifnull(eachProdDet.get(("Discount")),"0.0")).toDecimal();
total = (ifnull(eachProdDet.get("Total"),"0.0")).toDecimal();
productId = ifnull(eachProdDet.get("Product Id"),"");
linetax = (ifnull(eachProdDet.get("Tax"),"")).toDecimal();
mp = map();
mp.put("Product Id", productId);
mp.put("Quantity", quantity);
mp.put("List Price", listPrice);
mp.put(("Discount"), linediscount);
mp.put("Total", total);
mp.put("Tax", linetax);
mp.put("Net Total", netTotal);
pdlist.add(mp);
}
paramap = map();
paramap.put("Products", pdlist);
paramap.put("Subject", ifnull(respMap.get("Subject"),""));
paramap.put("CONTACTID", ifnull(respMap.get("CONTACTID"),""));
paramap.put("Terms and Conditions", ifnull(respMap.get("Terms and Conditions"),""));
paramap.put("Description", ifnull(respMap.get("Description"),""));
paramap.put("Tax", (ifnull(respMap.get("Tax"),"0.0")).toDecimal());
paramap.put("Adjustment", (ifnull(respMap.get("Adjustment"),"0.0")).toDecimal());
paramap.put(("Discount"), (ifnull(respMap.get(("Discount")),"0.0")).toDecimal());
paramap.put("Sub Total", (ifnull(respMap.get("Sub Total"),"0.0")).toDecimal());
paramap.put("Grand Total", (ifnull(respMap.get("Grand Total"),"0.0")).toDecimal());
createResp = zoho.crm.create("Invoices", paramap);
return "Invoice created successfully";Create purchase orders from Sales order.
Function type: Button
Function description: You can generate purchase orders from records in Sales order. This is helpful if you determine that a deal would go through.
How to get it to work:
Button placement: This button should be placed in the View page of the SalesOrder module.
Argument mapping: To configure this action,- Click Setup > Customization > Modules > Sales Orders > Links and Buttons > +Create new button.
- Enter the button name > Choose view page > Choose Writing Functions.
- Enter the name of the Function and click on Free flow scripting.
- Copy the code given below.
- Click Edit arguments.
- Enter the name as 'soId' and choose the value as 'Sales Order ID'.
- Click Done.
- Check the code script and click Save.
- In the Create your button page, click Save.
Script:
respMap = zoho.crm.getRecordById("SalesOrders", input.soId.toLong());
productDet=ifnull(respMap.get("product"),"");
productList=productDet.toJSONList();
pdlist=List();
for each eachProd in productList
{
eachProdDet=eachProd.toMap();
productDesc=ifnull(eachProdDet.get("Product Description"),"");
quantity=ifnull(eachProdDet.get("Quantity"),"0");
listPrice=(ifnull(eachProdDet.get("List Price"),"0.0")).toDecimal();
netTotal=(ifnull(eachProdDet.get("Net Total"),"0.0")).toDecimal();
linediscount=(ifnull(eachProdDet.get(("Discount")),"0.0")).toDecimal();
total=(ifnull(eachProdDet.get("Total"),"0.0")).toDecimal();
productId=ifnull(eachProdDet.get("Product Id"),"");
linetax=(ifnull(eachProdDet.get("Tax"),"")).toDecimal();
mp=map();
mp.put("Product Id",productId);
mp.put("Quantity",quantity);
mp.put("List Price",listPrice);
mp.put(("Discount"),linediscount);
mp.put("Total",total);
mp.put("Tax",linetax);
mp.put("Net Total",netTotal);
pdlist.add(mp);
}
paramap=map();
paramap.put("Products",pdlist);
paramap.put("Subject",ifnull(respMap.get("Subject"),""));
paramap.put("CONTACTID",ifnull(respMap.get("CONTACTID"),""));
paramap.put("Terms and Conditions",ifnull(respMap.get("Terms and Conditions"),""));
paramap.put("Description",ifnull(respMap.get("Description"),""));
paramap.put("Tax",(ifnull(respMap.get("Tax"),"0.0")).toDecimal());
paramap.put("Adjustment",(ifnull(respMap.get("Adjustment"),"0.0")).toDecimal());
paramap.put(("Discount"),(ifnull(respMap.get(("Discount")),"0.0")).toDecimal());
paramap.put("Sub Total",(ifnull(respMap.get("Sub Total"),"0.0")).toDecimal());
paramap.put("Grand Total",(ifnull(respMap.get("Grand Total"),"0.0")).toDecimal());
createResp = zoho.crm.create("PurchaseOrders", paramap);
return "Po created successfully";Sending mass emails from Leads or Contacts module.
Function type: Button
Function description: You can send emails to multiple records from the Leads or Contacts module list view page with just the click of a button.
How to get it to work:
Button placement: The button must be placed in the List view page of Leads or Contacts module.
Argument mapping: To configure this action,- Click Setup > Customization > Modules > Leads > Links and Buttons > +Create new button.
- Enter the button name > Choose List view page > Choose Writing Functions.
- Enter the name of the Function and click on Free flow scripting.
- Copy the code given below.
- Click Edit arguments.
- Enter the name as 'leadId' and choose the value as 'Lead ID'.
- Click Done.
- Check the code script and click Save.
- In the Create your button page, click Save.
Script:
leadIdsList = input.leadId.toList("|||");
for each leadIdStr in leadIdsList
{
resp = zoho.crm.getRecordById("Leads", leadIdStr.toLong());
email = ifnull(resp.get("Email"),"");
sendmail
(
To : email
From : zoho.adminuserid
Subject : "Subject of the email"
Message : "This is the message from Function send mail"
)
}
return "LeadID" + input.leadId;Update field and send email list view page.
Function type: Button
Function description: If you want to update multiple records and simultaneously send emails to them, you just need a button. Of course, along with this function.
How to get it to work:
Button placement: This button must be placed in the List view page of a Custom module.
Argument mapping: To configure this action,- Click Setup > Customization > Modules > Custom Module > Links and Buttons > +Create new button.
- Enter the button name > Choose view page > Choose Writing Functions.
- Enter the name of the Function and click on Free flow scripting.
- Copy the code given below.
- Click Edit arguments.
- Enter the name as 'custommoduleId' and choose the value as 'CustomModule ID'.
- Click Done.
- Check the code script and click Save.
- In the Create your button page, click Save.
Script:
IdsList = input.Id.toList("|||");
for each IdStr in IdsList
{
resp = zoho.crm.getRecordById("CustomModule1", IdStr.toLong());
customMap = map();
customMap.put("Record Status", "Approve");
updateResponse = zoho.crm.updateRecord("CustomModule1", IdStr, customMap);
email = ifnull(resp.get("Email"),"");
sendmail
(
To : email
From : zoho.adminuserid
Subject : "Approval Email"
Message : " )
}
return "Success";
Workflow-type Functions
Calculate commissions in Quotes.
Function Type: Workflow
Function description: The total commission generated by all the products of quotes will be displayed in the Quotes page. Hence, it becomes easier to view the total commission you receive without having to calculate manually.
How to get it to work: You must associate this Function under appropriate workflow rule to automatically update the Total commission of each product in Quotes module.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Quotes'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "quoteId" and the value as "Quote Id".
- Click Done.
- Check the code script and click Save.
Script:
quoteIdStr = input.quoteId.toString();
quoteMap = zoho.crm.getRecordById("Quotes", input.quoteId);
productDet = ifnull(quoteMap.get("product"),"");
productList = productDet.toJSONList();
value = 0.0;
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
qty = (ifnull(eachProdDet.get("Quantity"),"0")).toLong();
productId = ifnull(eachProdDet.get("Product Id"),"");
proDetails = zoho.crm.getRecordById("Products", productId.toLong());
commission = (ifnull(proDetails.get("Commission Rate"),"0.0")).toDecimal();
value = (value + commission * qty);
}
params = map(); params.put("Total Commission", value);
updateResp = zoho.crm.updateRecord("Quotes", quoteIdStr, params);Calculation of Taxes in Product Line items.
Function type: Workflow
Function description: You can calculate the tax amount for all the products and display them in the Invoices module.
How to get it to work: Associate this Function under appropriate workflow rule to calculate the Tax of each products in Invoices.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Invoices'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "invoiceId" and the value as "Invoice Id".
- Click Done.
- Check the code script and click Save.
Script:
invoiceIdStr = input.invoiceId.toString();
invoiceMap = zoho.crm.getRecordById("Invoices", input.invoiceId);
productDet = ifnull(invoiceMap.get("product"),"");
TotalTax = (ifnull(invoiceMap.get("Tax"),"0.0")).toDecimal();
TotalAdjustment = (ifnull(invoiceMap.get("Adjustment"),"0.0")).toDecimal();
TotalDiscount = (ifnull(invoiceMap.get(("Discount")),"0.0")).toDecimal();
productList = productDet.toJSONList();
sumPrice = 0.0;
price = 0.0;
value = 0.0;
pdlist = List();
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
discount = (ifnull(eachProdDet.get(("Discount")),"0.0")).toDecimal();
total = (ifnull(eachProdDet.get("Total"),"0.0")).toDecimal();
productId = ifnull(eachProdDet.get("Product Id"),"");
proDetails = zoho.crm.getRecordById("Products", productId.toLong());
Taxvalue = ifnull(proDetails.get("Taxes"),"");
if (Taxvalue == "VAT")
{
value = 12.5;
price = (price + total + 12.5 - discount);
}
else
{
if (Taxvalue == "Surcharge")
{
value = 0.625;
price = (price + total + 0.625 - discount);
}
else
{
value = 12.625;
price = (price + total + 0.625 + 12.5 - discount);
}
}
mp = map();
mp.put("Product Id", productId);
mp.put("Tax", value);
mp.put("Net Total", price);
pdlist.add(mp);
sumPrice = (sumPrice + price.toDecimal());
}
grandPrice = (sumPrice - TotalDiscount + TotalAdjustment + TotalTax);
paramap = map();
paramap.put("Products", pdlist);
paramap.put("Sub Total", sumPrice);
paramap.put("Grand Total", grandPrice);
updateResp = zoho.crm.updateRecord("Invoices", invoiceIdStr, paramap);Convert leads into records in other modules.
Function type: Workflow
Function description: You can convert leads into records of other modules such as Accounts, Contacts, Potentials, etc,automatically.
How to get it to work: Associate this Function under appropriate workflow rule to automatically convert Leads into Accounts, Contacts, etc.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Leads'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "leadId" and the value as "Lead Id".
- Click +Add argument and type the name as "Authtoken".
- Click "Specify custom value" and enter the CRM Authtoken in the box.
- Click Done.
- Check the code script and click Save.
Note
If you don't want to delete the lead record after it has been converted, please comment the last line of the script.
Script:
leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads", leadIdLong);
first = ifnull(leadDetails.get("First Name"),"");
last = ifnull(leadDetails.get("Last Name"),"");
name = first + " " + last;
AcccountMap = map();
AcccountMap.put(("Account Name"), ifnull(leadDetails.get("Company"),""));
AcccountMap.put("Annual Revenue", ifnull(leadDetails.get("Annual Revenue"),""));
AcccountMap.put("Billing City", ifnull(leadDetails.get("City"),""));
AcccountMap.put("Billing Country", ifnull(leadDetails.get("Country"),""));
AcccountMap.put("Description", ifnull(leadDetails.get("Description"),""));
AcccountMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
AcccountMap.put("Industry", ifnull(leadDetails.get("Industry"),""));
AcccountMap.put("Employees", ifnull(leadDetails.get("No of Employees"),""));
AcccountMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
AcccountMap.put("Rating", ifnull(leadDetails.get("Rating"),""));
AcccountMap.put("Billing State", ifnull(leadDetails.get("State"),""));
AcccountMap.put("Billing Street", ifnull(leadDetails.get("Street"),""));
AcccountMap.put("Billing Code", ifnull(leadDetails.get("Zip Code"),""));
AcccountMap.put("Website", ifnull(leadDetails.get("Website"),""));
AccountCreate = zoho.crm.create(("Accounts"), AcccountMap);
newaccountId = (AccountCreate).get("Id");
ContactMap = map();
ContactMap.put("First Name", ifnull(leadDetails.get("First Name"),""));
ContactMap.put("Last Name", ifnull(leadDetails.get("Last Name"),""));
ContactMap.put("Mailing City", ifnull(leadDetails.get("City"),""));
ContactMap.put("Mailing Country", ifnull(leadDetails.get("Country"),""));
ContactMap.put("Mailing State", ifnull(leadDetails.get("State"),""));
ContactMap.put("Mailing Street", ifnull(leadDetails.get("Street"),""));
ContactMap.put("Mailing Zip", ifnull(leadDetails.get("Zip Code"),""));
ContactMap.put("Description", ifnull(leadDetails.get("Description"),""));
ContactMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
ContactMap.put("Title", ifnull(leadDetails.get("Title"),""));
ContactMap.put("Email", ifnull(leadDetails.get("Email"),""));
ContactMap.put("Lead Source", ifnull(leadDetails.get("Lead Source"),""));
ContactMap.put("Mobile", ifnull(leadDetails.get("Mobile"),""));
ContactMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
ContactMap.put("Secondary Email", ifnull(leadDetails.get("Secondary Email"),""));
ContactMap.put("Skype ID", ifnull(leadDetails.get("Skype ID"),""));
ContactMap.put("Twitter", ifnull(leadDetails.get("Twitter"),""));
ContactMap.put("ACCOUNTID", newaccountId);
ContactCreate = zoho.crm.create("Contacts", ContactMap);
newcontactId = ContactCreate.get("Id");
PotentialMap = map();
PotentialMap.put("Potential Name", name);
PotentialMap.put("City", ifnull(leadDetails.get("City"),""));
PotentialMap.put("Country", ifnull(leadDetails.get("Country"),""));
PotentialMap.put("State", ifnull(leadDetails.get("State"),""));
PotentialMap.put("Street", ifnull(leadDetails.get("Street"),""));
PotentialMap.put("Zipcode", ifnull(leadDetails.get("Zip Code"),""));
PotentialMap.put("Description", ifnull(leadDetails.get("Description"),""));
PotentialMap.put("Lead Source", ifnull(leadDetails.get("Lead Source"),""));
PotentialMap.put("ACCOUNTID", newaccountId);
PotentialMap.put("CONTACTID", newcontactId);
PotentialCreate = zoho.crm.create("Potentials", PotentialMap);
url = getUrl("https://crm.zoho.com/crm/private/xml/Leads/deleteRecords?authtoken=" + input.Authtoken + "&scope=crmapi&id=" + input.leadId);Create Contacts from Custom Modules.
Function type: Workflow
Function description: You can directly create a Contact record from the information available from any custom module automatically.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create contacts from custom modules.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Custom Module'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "customId" and the value as "CustomModule Id".
- Click Done.
- Check the code script and click Save.
Script:
CustomModuleDetails = zoho.crm.getRecordById("CustomModule1", input.customId);
ContactMap = map();
ContactMap.put("First Name", ifnull(CustomModuleDetails.get("First Name"),""));
ContactMap.put("Last Name", ifnull(CustomModuleDetails.get("Last Name"),""));
ContactMap.put("Email", ifnull(CustomModuleDetails.get("Email"),""));
ContactMap.put("Date", ifnull(CustomModuleDetails.get("Date"),""));
ContactMap.put("Birth Date", ifnull(CustomModuleDetails.get("Birth Date"),""));
ContactMap.put("Mailing Street", ifnull(CustomModuleDetails.get("Mailing Street"),""));
ContactMap.put("Mailing City", ifnull(CustomModuleDetails.get("Mailing City"),""));
ContactMap.put("Mailing State", ifnull(CustomModuleDetails.get("Mailing State"),""));
ContactMap.put("Mailing Zip", ifnull(CustomModuleDetails.get("Mailing Zip"),""));
ContactMap.put("Phone", ifnull(CustomModuleDetails.get("Phone"),""));
ContactMap.put("SMOWNERID", ifnull(CustomModuleDetails.get("SMOWNERID"),""));
ContactMap.put("Company Name", ifnull(CustomModuleDetails.get("Company Name"),""));
ContactMap.put("Industry Type", ifnull(CustomModuleDetails.get("Industry Type"),""));
ContactCreate = zoho.crm.create("Contacts", ContactMap);Create a Custom Module from a Custom Module.
Function type: Workflow
Function description: You can create a new Custom Module from the records of another Custom Module. This is especially useful in the case where you need to transfer information from one module to another. Let the Function do that for you.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create a Custom Module with the records from another Custom Module.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Custom Module'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "CustommoduleId" and the value as "CustomModule Id".
- Click Done.
- Check the code script and click Save.
Script:
CustommoduleDetails = zoho.crm.getRecordById("CustomModule1", input.CustommoduleId);
createMap = map();
createMap.put("CustomModule2 Name", ifnull(CustommoduleDetails.get("Custom Name"),""));
createMap.put("SMOWNERID", ifnull(CustommoduleDetails.get("SMOWNERID"),""));
createMap.put("Phone", ifnull(CustommoduleDetails.get("Phone"),""));
createMap.put("Email", ifnull(CustommoduleDetails.get("Email"),""));
createCustomModule = zoho.crm.create("CustomModule2", createMap);Create follow-up activities.
Function type: Workflow
Function description: You can create follow up activities for your Contacts. This is one of the most essential and useful Function available since it makes the lives of countless agents easier.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create followup activities for the selected contact record.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Contacts'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "contactId" and the value as "Contact Id".
- Click Done.
- Check the code script and click Save.
Script:
contactIdStr = input.contactId.toString();
TaskDetails = zoho.crm.getRelatedRecords("Tasks", "Contacts", contactIdStr);
for each Task in TaskDetails
{
taskMap = map();
taskMap.put("Task Owner", ifnull(Task.get("Task Owner"),""));
taskMap.put("Subject", (Task.get("Subject")) + " Followup ");
taskMap.put("Due Date", ifnull(Task.get("Due Date"),""));
taskMap.put("Status", ifnull(Task.get("Status"),""));
taskMap.put("Priority", ifnull(Task.get("Priority"),""));
taskMap.put("SMOWNERID", ifnull(Task.get("SMOWNERID"),""));
taskMap.put("CONTACTID", contactIdStr);
taskMap.put("SEID", ifnull(Task.get("RELATEDTOID"),""));
taskMap.put("SEMODULE", ifnull(Task.get("SEMODULE"),""));
createTask = zoho.crm.create("Tasks", taskMap);
}
EventDetails = zoho.crm.getRelatedRecords("Events", "Contacts", contactIdStr);
for each Event in EventDetails
{
eventMap = map();
eventMap.put("Subject", (Event.get("Subject")) + " Followup ");
eventMap.put("SMOWNERID", ifnull(Event.get("SMOWNERID"),""));
eventMap.put("Start DateTime", (ifnull(Event.get("Start DateTime"),"")).toTime());
eventMap.put("End DateTime", (ifnull(Event.get("End DateTime"),"")).toTime());
eventMap.put("CONTACTID", contactIdStr);
eventMap.put("SEID", ifnull(Event.get("RELATEDTOID"),""));
eventMap.put("SEMODULE", ifnull(Event.get("SEMODULE"),""));
createEvent = zoho.crm.create("Events", eventMap);
}
CallDetails = zoho.crm.getRelatedRecords("Calls", "Contacts", contactIdStr);
for each Call in CallDetails
{
Callstatus = Call.get("Call Status");
if ((Callstatus == "Scheduled") || (Callstatus == "Overdue"))
{
callMap = map();
callMap.put("Subject", (Call.get("Subject")) + " Followup ");
callMap.put("SMOWNERID", ifnull(Call.get("SMOWNERID"),""));
callMap.put("Call Type", ifnull(Call.get("Call Type"),""));
callMap.put("whichCall", "ScheduleCall");
callMap.put("Call Start Time", ifnull(Call.get("Call Start Time"),""));
callMap.put("Call Duration", ifnull(Call.get("Call Duration"),""));
callMap.put("CONTACTID", contactIdStr);
callMap.put("SEID", ifnull(Call.get("RELATEDTOID"),""));
callMap.put("SEMODULE", ifnull(Call.get("SEMODULE"),""));
createCall = zoho.crm.create("Calls", callMap);
}
else
{
callMap = map();
callMap.put("Subject", (Call.get("Subject")) + " Followup ");
callMap.put("SMOWNERID", ifnull(Call.get("SMOWNERID"),""));
callMap.put("Call Type", ifnull(Call.get("Call Type"),""));
callMap.put("Call Start Time", ifnull(Call.get("Call Start Time"),""));
callMap.put("Call Duration", ifnull(Call.get("Call Duration"),""));
callMap.put("CONTACTID", contactIdStr);
callMap.put("SEID", ifnull(Call.get("RELATEDTOID"),""));
callMap.put("SEMODULE", ifnull(Call.get("SEMODULE"),""));
createCall = zoho.crm.create("Calls", callMap);
}
}Create Invoices from Purchase orders.
Function type: Workflow
Function description: You can generate invoices for purchase orders automatically by defining this Function.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create invoices.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Purchase Orders'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "poId" and the value as "Purchase Order Id".
- Click Done.
- Check the code script and click Save.
Script:
respMap = zoho.crm.getRecordById("PurchaseOrders", input.poId.toLong());
productDet = ifnull(respMap.get("product"),"");
productList = productDet.toJSONList();
pdlist = List();
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
productDesc = ifnull(eachProdDet.get("Product Description"),"");
quantity = ifnull(eachProdDet.get("Quantity"),"0");
listPrice = (ifnull(eachProdDet.get("List Price"),"0.0")).toDecimal();
netTotal = (ifnull(eachProdDet.get("Net Total"),"0.0")).toDecimal();
linediscount = (ifnull(eachProdDet.get(("Discount")),"0.0")).toDecimal();
total = (ifnull(eachProdDet.get("Total"),"0.0")).toDecimal();
productId = ifnull(eachProdDet.get("Product Id"),"");
linetax = (ifnull(eachProdDet.get("Tax"),"")).toDecimal();
mp = map();
mp.put("Product Id", productId);
mp.put("Quantity", quantity);
mp.put("List Price", listPrice);
mp.put(("Discount"), linediscount);
mp.put("Total", total);
mp.put("Tax", linetax);
mp.put("Net Total", netTotal);
pdlist.add(mp);
}
paramap = map();
paramap.put("Products", pdlist);
paramap.put("Subject", ifnull(respMap.get("Subject"),""));
paramap.put("CONTACTID", ifnull(respMap.get("CONTACTID"),""));
paramap.put("Terms and Conditions", ifnull(respMap.get("Terms and Conditions"),""));
paramap.put("Description", ifnull(respMap.get("Description"),""));
paramap.put("Tax", (ifnull(respMap.get("Tax"),"0.0")).toDecimal());
paramap.put("Adjustment", (ifnull(respMap.get("Adjustment"),"0.0")).toDecimal());
paramap.put(("Discount"), (ifnull(respMap.get(("Discount")),"0.0")).toDecimal());
paramap.put("Sub Total", (ifnull(respMap.get("Sub Total"),"0.0")).toDecimal());
paramap.put("Grand Total", (ifnull(respMap.get("Grand Total"),"0.0")).toDecimal());
createResp = zoho.crm.create("Invoices", paramap);Create leads from a contact with all related data.
Function type: Workflow
Function description: You can create leads from contact records instantly. This would certainly be helpful if you want to make a new deal with someone you already know.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create lead records from contacts.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Contacts'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "contactId" and the value as "Contact Id".
- Click Done.
- Check the code script and click Save.
Script:
contactIdStr = input.contactId.toString();
contactDetails = zoho.crm.getRecordById("Contacts", input.contactId);
leadMap = map();
leadMap.put("Last Name", ifnull(contactDetails.get("Last Name"),""));
leadMap.put("First Name", ifnull(contactDetails.get("First Name"),""));
leadMap.put("SMOWNERID", ifnull(contactDetails.get("SMOWNERID"),""));
leadMap.put("Email", ifnull(contactDetails.get("Email"),""));
leadMap.put("Third Email", ifnull(contactDetails.get("Third Email"),""));
leadMap.put("Secondary Email", ifnull(contactDetails.get("Second Email"),""));
leadMap.put("Phone", ifnull(contactDetails.get("Phone"),""));
leadMap.put("Lead Status", ifnull(contactDetails.get("Contact Status"),""));
leadMap.put("Created On", ifnull(contactDetails.get("Created On"),""));
leadMap.put("Notes", ifnull(contactDetails.get("Notes"),""));
leadMap.put("Skype ID", ifnull(contactDetails.get("Skype ID"),""));
leadMap.put("Wechat ID", ifnull(contactDetails.get("Wechat ID"),""));
createLead = zoho.crm.create("Leads", leadMap);
id = createLead.get("Id");
contactRelNotes = zoho.crm.getRelatedRecords("Notes", "Contacts", contactIdStr);
countVal = 0;
for each ele in contactRelNotes
{
countVal = (countVal + 1);
notemap = map();
notemap.put("entityId", id);
notemap.put("Note Title", ifnull(ele.get("Title")," "));
notemap.put("Note Content", ifnull(ele.get("Note Content")," "));
notecreate = zoho.crm.create("Notes", notemap);
}
TaskDetails = zoho.crm.getRelatedRecords("Tasks", "Contacts", contactIdStr);
for each ele in TaskDetails
{
TaskId = ele.get("ACTIVITYID");
taskMap = map();
taskMap.put("SEID", id);
taskMap.put("SEMODULE", "CustomModule2");
UpdateTask = zoho.crm.updateRecord("Tasks", TaskId, taskMap);
}
EventDetails = zoho.crm.getRelatedRecords("Events", "Contacts", contactIdStr);
for each ele in EventDetails
{
eventId = ele.get("ACTIVITYID");
eventMap = map();
eventMap.put("SEID", id);
eventMap.put("SEMODULE", "CustomModule2");
UpdateEvent = zoho.crm.updateRecord("Events", eventId, eventMap);
}
CallDetails = zoho.crm.getRelatedRecords("Calls", "Contacts", contactIdStr);
for each ele in CallDetails
{
callId = ele.get("ACTIVITYID");
callMap = map();
callMap.put("SEID", id);
callMap.put("SEMODULE", "CustomModule2");
UpdateCall = zoho.crm.updateRecord("Calls", callId, callMap);
}Create Purchase orders from Sales Order.
Function type: Workflow
Function description: You can generate purchase orders from Sales order module. Usually this function is used after a deal is confirmed.
How to get it to work: Associate this Function under appropriate workflow rule to automatically create Purchase Order records from Sales Order module.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Sales Orders'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "soId" and the value as "Sales Order Id".
- Click Done.
- Check the code script and click Save.
Script:
respMap = zoho.crm.getRecordById("SalesOrders", input.soId.toLong());
productDet = ifnull(respMap.get("product"),"");
productList = productDet.toJSONList();
pdlist = List();
for each eachProd in productList
{
eachProdDet = eachProd.toMap();
productDesc = ifnull(eachProdDet.get("Product Description"),"");
quantity = ifnull(eachProdDet.get("Quantity"),"0");
listPrice = (ifnull(eachProdDet.get("List Price"),"0.0")).toDecimal();
netTotal = (ifnull(eachProdDet.get("Net Total"),"0.0")).toDecimal();
linediscount = (ifnull(eachProdDet.get(("Discount")),"0.0")).toDecimal();
total = (ifnull(eachProdDet.get("Total"),"0.0")).toDecimal();
productId = ifnull(eachProdDet.get("Product Id"),"");
linetax = (ifnull(eachProdDet.get("Tax"),"")).toDecimal();
mp = map();
mp.put("Product Id", productId);
mp.put("Quantity", quantity);
mp.put("List Price", listPrice);
mp.put(("Discount"), linediscount);
mp.put("Total", total);
mp.put("Tax", linetax);
mp.put("Net Total", netTotal);
pdlist.add(mp);
}
paramap = map();
paramap.put("Products", pdlist);
paramap.put("Subject", ifnull(respMap.get("Subject"),""));
paramap.put("CONTACTID", ifnull(respMap.get("CONTACTID"),""));
paramap.put("Terms and Conditions", ifnull(respMap.get("Terms and Conditions"),""));
paramap.put("Description", ifnull(respMap.get("Description"),""));
paramap.put("Tax", (ifnull(respMap.get("Tax"),"0.0")).toDecimal());
paramap.put("Adjustment", (ifnull(respMap.get("Adjustment"),"0.0")).toDecimal());
paramap.put(("Discount"), (ifnull(respMap.get(("Discount")),"0.0")).toDecimal());
paramap.put("Sub Total", (ifnull(respMap.get("Sub Total"),"0.0")).toDecimal());
paramap.put("Grand Total", (ifnull(respMap.get("Grand Total"),"0.0")).toDecimal());
createResp = zoho.crm.create("PurchaseOrders", paramap);Update all related contact fields when a field is updated in Accounts.
Function type: Workflow
Function description: With this Function, it is possible to update all of the related fields of a particular record when it is updated in the Accounts module.
How to get it to work: Associate this Function under appropriate workflow rule to automatically update all related contact fields.
- Click Setup > Automation > Actions > Functions > +Configure Function > Write your own > Choose 'Module to be associated as 'Accounts'.
- Enter a name for the Function and click on 'Free flow scripting'.
- Copy the code script given below.
- Click 'Edit arguments'.
- Enter the name as "accountId" and the value as "Account Id".
- Click +Add argument and type the name as "type".
- Enter the value as "Account Type".
- Click Done.
- Check the code script and click Save.
Script:
accountIdStr = input.accountId.toString();
relatedcontacts = zoho.crm.getRelatedRecords("Contacts", ("Accounts"), accountIdStr);
info relatedcontacts;
for each ele in relatedcontacts
{
contactId = ifnull(ele.get("id"),"");
mp = map();
mp.put("Contact Type", input.type );
update = zoho.crm.updateRecord("Contacts", contactId, mp);
info mp;
info update;
}