Welcome back everyone!
Business scenario
Having a clear refund policy goes a long way in gaining customer trust. Depending upon the line of business, the refund window might vary. This is even more important in the case of online purchases where customers get to see and feel the product only after making the purchase.
The Deals module in CRM helps track the revenue associated with the sales executives. By taking a report of all the 'won' businesses pertaining to a month, you'll be able to calculate the revenue associated with the sales executives concerned. Recently one of our users asked if there is any working solution to track refunds. Typically, the refund period is 30 days and the refunds have to be tracked without affecting the revenue numbers from the preceding month. Hence updating the closed Deal stage to a "Refunded" stage won't work.
A simple solution to this problem is to clone the won deal that needs to be refunded and make the following updates in the cloned deal:
- Update the deal value in negative to account for the refund amount
- Update the deal closing date to current date.
- Update the status of the cloned deal to "Refunded".
This leaves the revenue numbers of the preceding months and the sales forecast for the current month intact while accounting for the refunds too. Expecting your sales executives do all these steps manually is a tall order. Fret not, the Function I'm sharing this week helps you do all these steps at the click of a button.
Pre-requisites
- Create a Deal Status named "Refunded".
Getting started with the function
- Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
- Provide a name for the button. For example: "Refund". Add a description(optional).
- Select the placement of the button as View page.
- Select the action to be performed as "Writing function".
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “dealId” and select the value as “Deal Id”.
- Click Save&Execute Script.
- Save the script.
- Select the profiles who can view this button.
- Click Save.
The Code
-----------------------------------------------------------------------------------------------------------------------
dealDetails = zoho.crm.getRecordById("Deals", input.dealId.toLong());
mp=map();
mp.put("Deal_Name",ifnull(dealDetails.get("Deal_Name"),""));
mp.put("Owner",ifnull(dealDetails.get("Owner"),"").get("id"));
mp.put("Account_Name",ifnull(dealDetails.get("Account_Name"),"").get("id"));
mp.put("Contact_Name",ifnull(dealDetails.get("Contact_Name"),"").get("id"));
mp.put("Amount","-"+ifnull(dealDetails.get("Amount"),""));
mp.put("Stage","Refunded");
mp.put("Closing_Date",today);
create=zoho.crm.create("Deals", mp);
info mp;
info create;
return "success";
-----------------------------------------------------------------------------------------------------------------------
Before Refund
After Refund
Note
- The code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.
Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Do check out other functions shared in this series here.
See you all next week with another interesting function. Ciao!