Function-30: Keep track of your business details with a Company or a Contact.

Function-30: Keep track of your business details with a Company or a Contact.



Welcome back everyone!

Recently we had made an announcement regarding the renaming of Custom Functions to Functions. Check this link to know the implications regarding the change.

Last week, we learnt how to create Purchase Orders for Individual Products instead of a Contact or Account, from a Sales Order. This week, let's look at a custom function that lets you update your Account and Contact records on the products involved in the transaction, for each related Invoice generated.

Business scenario:

Keeping a check on the working capital lets you have an overview of your inventory and you can make plans to maintain your stocks. The vendor management side of CRM helps you with that. However, moving further on your business, you would have to keep regular contact with some of your patrons. Not just patrons, for each deal made with a company(Account) or a contact, there is a need to keep records of the products/services involved in the transaction. Although there is a related list that lets you do that, all of the information are Inventory-centric and not Contact or Account-centric. In other words, some additional information about the product, the exact products involved in the deal cannot be captured perfectly.

This procedure is vital in a business as it helps in gathering data for analyzing and forming better long-term business strategies. Assume there are 2 Customers, A and B, who buy 3 products each. You create an 2 Invoices, one for each. Your inventory gets updated and shows the remaining stock, but it doesn't show to whom the products were delivered. Through this function, you can use the information from the Invoice to place the product details of the transaction within the Contact or Account(Company) record to which the Invoice was sent to.

Setting this function as a button is not a practical, so we suggest placing this function in a Workflow rule to incorporate this process into your business process.

Getting started with the custom function:
  • Go to Setup > Automation > Functions > Configure Function.
  • Select "Write your own".
  • Provide a name for the function. For example: “Product details from Invoice to Contact/Account”. Add a description(optional).
  • Select the module as "Invoice". Add a description (optional).
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “invoiceId” and select the value as “Invoice Id”.
  • Enter the name as “acctId” and select the value as “Account Id”.
  • Enter the name as “contId” and select the value as “Contact Id”.
  • Click Save&Execute Script.
  • Click Save.

The script:

Code for Version 2.0 API:

respMap = zoho.crm.getRecordById("Invoices", input.invoiceId.toLong());
accountId = ifnull(respMap.get("Account_Name"),"").get("id");
contactId = ifnull(respMap.get("Contact_Name"),"").get("id");
productDet=ifnull(respMap.get("Product_Details"),"");
pdlist=List();
for each eachProd in productDet
{
productvalue = eachProd.get("product");
proid = productvalue.get("id");
mp=map();
mp.put("PRODUCTID",input.proid);
resp = zoho.crm.updateRelatedRecord("Products",proid,"Accounts",accountId.toLong(),mp);
info resp;
resp1 = zoho.crm.updateRelatedRecord("Products",proid,"Contacts",contactId.toLong(),mp);
info resp1;
}

Code for Version 1.0 API:

authtoken = "xxxxxxxxxxxxxxxxxxx";
respMap = getUrl((((" https://crm.zoho.com/crm/private/xml/Invoices/getRecordById?authtoken=") + authtoken) + "&scope=crmapi&id=") + input.invoiceId);
productDetails = respMap.executeXPath("/response/result/Invoices/row/FL[@val ='Product Details']/product").toList("-|-");
countVal = 0;
paramsmap = map();
paramsmap.put("authtoken", authtoken);
paramsmap.put("scope", "crmapi");
paramsmap.put("id", input.acctId);
paramsmap.put("relatedModule", "Products");
test = "<Products>";
for each item in productDetails
{
countVal = (countVal + 1);
productIdStr = item.executeXPath("/product/FL[@val ='Product Id']/text()");
info productIdStr;
productId = productIdStr.toLong();
test = (test + "<row no=\"" + (countVal)) + "\">";
test = test + "<FL val=\"PRODUCTID\">" + productId + "</FL>";
test = test + "</row>";
}
test = test + "</Products>";
paramsmap.put("xmlData", test);
info url;
paramsmap1 = map();
paramsmap1.put("authtoken", authtoken);
paramsmap1.put("scope", "crmapi");
paramsmap1.put("id", input.contId);
paramsmap1.put("relatedModule", "Products");
test1 = "<Products>";
for each item in productDetails
{
countVal = (countVal + 1);
productIdStr = item.executeXPath("/product/FL[@val ='Product Id']/text()");
info productIdStr;
productId = productIdStr.toLong();
test1 = (test1 + "<row no=\"" + (countVal)) + "\">";
test1 = test1 + "<FL val=\"PRODUCTID\">" + productId + "</FL>";
test1 = test1 + "</row>";
}
test1 = test1 + "</Products>";
paramsmap1.put("xmlData", test1);
info url1;


Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this series here.

See you all next week with another interesting custom function. Ciao! 

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this  announcement  for more. We've updated the post to include the Version 2.0 compatible Function.

    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

                                                            • How to reach the official Zoho Support channels and avoid fake ones.

                                                              Dear Customers, Thanks a lot for choosing Zoho! Our applications are built to help achieve your day-to-day business goals. We are committed to engaging with you, to understand and develop solutions that enhance your productivity.  We are happy and ready to help you use our services effectively. Understanding and avoiding fake support Just like using popular bank names and financial applications for phishing purposes, using Zoho and claiming to be providing Zoho Support or services with false numbers
                                                            • Function #35: Close all tasks associated with a lead and create a new task.

                                                              Welcome back everyone! Last week, we learnt how to close all tasks of a deal depending upon the deal stage. This week, let's look at a custom function that lets you close all of the tasks associated with a lead while simultaneously creating a new task, like when you need to halt all progress towards a lead while the lead is not available at the moment but create a reminder task. Business scenario: The success of a company, in one way or another, is determined by the leads it gets. Each lead is just
                                                            • Zoho CRM Webinar - Redesigning Daily User Experiences with Canvas

                                                              &lt;br&gt; Your users across roles use the CRM for day-to-day tasks that are necessary. Whether they perform their tasks on time, the right way, or at all depends on a lot of factors, including User Experience. Many businesses struggle with rigid layouts,
                                                            • Join us at the Canada ZUG Meetup: What’s New in Zoho CRM

                                                              Hello Zoho Community! Start your year with fresh insights into Zoho CRM’s latest updates and tools. Whether you're a CRM beginner or a experienced user, this meetup is crafted to help you optimise your processes and leverage new features. Explore practical
                                                            • CRM Hack #2: Automate sending of birthday greetings to your customers.

                                                                Hello everyone! What sets you apart as a sales person is your ability to add that personal touch to your business relationship with your customers. Sending a gift on a special day, or leaving a note wishing them on their birthdays, are small, yet significant actions that show your customers that you care. And these are actions done without any expectations :) You must be engaging with a lot of customers and it is highly unlikely that they all are your friends on Facebook or some social channel,


                                                            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

                                                                                                              • Add multiple users to a task

                                                                                                                When I´m assigning a task it is almost always related to more than one person. Practical situation: When a client request some improvement the related department opens the task with the situation and people related to it as the client itself, the salesman
                                                                                                              • A Roundup of Zoho Sprints 2025

                                                                                                              • Issue with WhatsApp Template Approval and Marketing Message Limit in Zoho Bigin

                                                                                                                We are facing issues while creating and using WhatsApp message templates through Zoho Bigin, and we request your clarification and support regarding the same. 1. Utility Template Approval Issue Until December, we were able to create WhatsApp templates
                                                                                                              • Zoho desk desktop application

                                                                                                                does zoho desk has a destop applicaion?
                                                                                                              • Sorting Custom Date in API isn't working w pagination limit

                                                                                                                How can we sort a custom field with DATE using pagination? Starting at page=1 then moving to page=2 with a limit of 10 each, its all messed up and even shows some of the same records as page 1? https://www.zohoapis.com/crm/v2/INVOICE_MODULE/search?criteria=(FM_Contact_ID:equals:1234)&sort_by=Invoice_Date&sort_order=desc&per_page=10&page='
                                                                                                              • SAP Business One(B1) integration is now live in Zoho Flow

                                                                                                                We’re excited to share that SAP Business One (B1) is now available in Zoho Flow! This means you can now build workflows that connect SAP B1 with other apps and automate routine processes without relying on custom code. Note: SAP Business One integration
                                                                                                              • How can i resend a campaign to only one of the recipients on the original campaign

                                                                                                                How can i resend a campaign to only one of the recipients on the original campaign ? Sincererly, Mike
                                                                                                              • Notes badge as a quick action in the list view

                                                                                                                Hello all, We are introducing the Notes badge in the list view of all modules as a quick action you can perform for each record, in addition to the existing Activity badge. With this enhancement, users will have quick visibility into the notes associated
                                                                                                              • Enhancement in Role and Profile mapping of agents in Sandbox

                                                                                                                Hello everyone! We have brought in a modification in the way users are mapped to a particular role and profile in Sandbox. What has changed? When agents are copied from production to Sandbox: If a user's current role and profile is available in Sandbox,
                                                                                                              • The reason I switched away from Zoho Notebook

                                                                                                                My main reason for switching to Zoho was driven by three core principles: moving away from US-based products, keeping my data within India as much as possible, and supporting Indian companies. With that intent, I’ve been actively de-Googling my digital
                                                                                                              • Decimal places settings for exchange rates

                                                                                                                Hello, We are facing issues while matching vendor payments with banking feeds. As we often import products/services exchange rate comes into play. Currently, ZOHO allows only six digits for decimal places. We feel that conversions like JPY to INR require
                                                                                                              • Zoho removed ability to see all Scheduled Reports!

                                                                                                                If you are not the owner of a scheduled report, Zoho recently removed the capability to see each scheduled report. As an admin who relies on seeing all scheduled reports being sent, this is a terrible update. Now I cannot see ANY scheduled reports...even the ones I am being sent!!  This should be a setting for admins to control.  This is a bad update.
                                                                                                              • Please can the open tasks be shown in each customer account at the top.

                                                                                                                Hi there This has happened before, where the open tasks are no longer visible at the top of the page for each customer in the CRM. They have gone missing previously and were reinstated when I asked so I think it's just after an update that this feature
                                                                                                              • Automate Backups

                                                                                                                This is a feature request. Consider adding an auto backup feature. Where when you turn it on, it will auto backup on the 15-day schedule. For additional consideration, allow for the export of module data via API calls. Thank you for your consideration.
                                                                                                              • GCLID and Zoho Bookings

                                                                                                                Is there anyway to embed a Zoho Bookings signup on a landing page and pass the GCLID information? More specifically, can this be done using auto-tagging and not manual tagging the GCLID? I know Zappier has an integration to do this but is there a better
                                                                                                              • Merge Items

                                                                                                                Is there a work around for merging items? We currently have three names for one item, all have had a transaction associated so there is no deleting (just deactivating, which doesn't really help. It still appears so people are continuing to use it). I also can't assign inventory tracking to items used in past transactions, which I don't understand, this is an important feature moving forward.. It would be nice to merge into one item and be able to track inventory. Let me know if this is possible.
                                                                                                              • Create PO from an invoice

                                                                                                                We are a hardware and software sales company which receives orders over the internet. We drop ship most of our products from a warehouse outside of our company. Our orders get sync'd into Zoho from our store via onesaas as invoices. It would be great
                                                                                                              • Blueprint or Validation Rules for Invoices in Zoho Books

                                                                                                                Can I implement Blueprint or Validation Rules for Invoices in Zoho Books? Example, use case could be, Agent confirms from client that payment is done, but bank only syncs transactions tomorrow. in this case, Agent can update invoice status to done, and
                                                                                                              • Resetting auto-number on new year

                                                                                                                Hi everyone! We have an auto-number with prefix "D{YYYY}-", it generates numbers like D2025-1, D2025-2, etc... How can we have it auto-reset at the beginning of the next year, so that it goes to D2026-1? Thanks!
                                                                                                              • Delivery and handling of documents e-stamped using Zoho Sign

                                                                                                                Hello everyone! Zoho Sign makes it easy to pay non judicial stamp duty online and automatically attach the digitally generated e-stamp challan to electronic documents. We also manage the delivery of physical e-stamped papers. We periodically receive these
                                                                                                              • The Social Wall: December 2025

                                                                                                                Hello everyone! As we wrap up the final edition of the Social Wall for 2025, it’s the perfect time to look at what went live during December. QR code generator From paying for coffee to scanning metro tickets, QR codes are everywhere and have made everyday
                                                                                                              • Custom AI solutions with QuickML for Zoho CRM

                                                                                                                Hello everyone, Earlier, we introduced Custom AI Solutions in CRM that let you access QuickML for your custom AI needs. Building on that foundation, we’ve now enabled a deeper integration: QuickML models can be seamlessly integrated into CRM, and surface
                                                                                                              • Helper Functions and DRY principle

                                                                                                                Hello everyone, I believe Deluge should be able to use 'Helper functions' inside the main function. I know I can create different standalones, but this is not helpful and confusing. I don't want 10000 different standalones, and I dont want to have to
                                                                                                              • Add specific field value to URL

                                                                                                                Hi Everyone. I have the following code which is set to run from a subform when the user selects a value from a lookup field "Plant_Key" the URL opens a report but i want the report to be filtered on the matching field/value. so in the report there is
                                                                                                              • Introducing workflow automation for the Products module

                                                                                                                Greetings, I hope all of you are doing well. We're happy to announce a few recent enhancements we've made to Bigin's Products module. The Products module in Bigin now supports Workflows, enabling you to automate routine actions. Along with this update,
                                                                                                              • Power up your Kiosk Studio with Real-Time Data Capture, Client Scripts & More!

                                                                                                                Hello Everyone, We’re thrilled to announce a powerful set of enhancements to Kiosk Studio in Zoho CRM. These new updates give you more flexibility, faster record handling, and real-time data capture, making your Kiosk flows smarter and more efficient
                                                                                                              • Zia Formula Expression Generator for Formula fields

                                                                                                                Hello everyone! Formula fields are super useful when you want your CRM to calculate things for you but writing the expression is where most people slow down. You know what you want, but you’re not fully sure which function to use, how the syntax should
                                                                                                              • Where is the settings option in zoho writer?

                                                                                                                hi, my zoho writer on windows has menu fonts too large. where do i find the settings to change this option? my screen resolution is correct and other apps/softwares in windows have no issues. regards
                                                                                                              • CRM project association via deluge

                                                                                                                I have created a workflow in my Zoho CRM for closing a deal. Part of this workflow leverages a deluge script to create a project for our delivery team. Creating the project works great however, after or during the project creation, I would like to associate
                                                                                                              • Issue with Zoho Creator Form Full-Screen View in CRM Related List Integration

                                                                                                                Hi Team, We have created a custom application in Zoho Creator and integrated it into Zoho CRM as a related list under the Vendor module, which we have renamed as Consignors. Within the Creator application, there is a form named “Pickup Request.” Inside
                                                                                                              • Wrapping up 2025 on a high note: CRM Release Highlights of the year

                                                                                                                Dear Customers, 2025 was an eventful year for us at Zoho CRM. We’ve had releases of all sizes and impact, and we are excited to look back, break it down, and rediscover them with you! Before we rewind—we’d like to take a minute and sincerely thank you
                                                                                                              • Directly Edit, Filter, and Sort Subforms on the Details Page

                                                                                                                Hello everyone, As you know, subforms allow you to associate multiple line items with a single record, greatly enhancing your data organization. For example, a sales order subform neatly lists all products, their quantities, amounts, and other relevant
                                                                                                              • Customer Parent Account or Sub-Customer Account

                                                                                                                Some of clients as they have 50 to 300 branches, they required separate account statement with outlet name and number; which means we have to open new account for each branch individually. However, the main issue is that, when they make a payment, they
                                                                                                              • Drop Down Value

                                                                                                                Hi, May I know why Zoho Flow treat this drop down as number and not as string. If so, how can I fetch the right value for filtering. This field is from Creator, in Creator upon checking by default it is a string since it's not a lookup field.
                                                                                                              • Projects custom colors replaced by default orange

                                                                                                                Since yesterday, projects uploaded to Zoho, to which I had assigned a custom color, have lost the customization and reverted to the default color (orange). Has anyone else had the same problem? If so, how did you resolve it?
                                                                                                              • How to manage task lists in Zoho Desk?

                                                                                                                Hello, I use Zoho Desk for IT customer support. I have a list of standard operating procedures (SOPs), including SOPs for onboarding new users, offboarding users, losing a device, etc. These are lists of tasks to be performed depending on the situation.
                                                                                                              • Creating a Chart from a Report

                                                                                                                In Zoho Analytics, is it possible to create a chart from a Pivot View report? We are looking to use Zoho Analytics to replace Excel for Sales reports and would like to be able to show both the table and the chart together.
                                                                                                              • Restrict Users access to login into CRM?

                                                                                                                I’m wanting my employees to be able to utilize the Zoho CRM Lookup field within Zoho Forms. For them to use lookup field in Zoho Forms it is my understanding that they need to be licensed for Forms and the CRM. However, I don’t want them to be able to
                                                                                                              • how to change the page signers see after signing a document in zoho sign

                                                                                                                Hello, How can I please change the page a signer sees after signing a document in Zoho Sign? I cannot seem to find it. As it is now, it shows a default landing page "return to Zoho Sign Home". Thanks!
                                                                                                              • Holidays - Cannot Enter Two Holidays on Same Day

                                                                                                                I have a fairly common setup, where part-time employees receive 1/2 day's pay on a holiday and full-time employees receive a full day's pay. Historically, I've been able to accommodate this by entering two separate holidays, one that covers full-time
                                                                                                              • Next Page