diff --git a/Deluge Functions/Buttons/convert_record_to_other_module.ds b/Deluge Functions/Buttons/convert_record_to_other_module.ds new file mode 100644 index 0000000..4d896b6 --- /dev/null +++ b/Deluge Functions/Buttons/convert_record_to_other_module.ds @@ -0,0 +1,52 @@ +//Anything within curly brackets will need to be replaced to the correct module, field, or variable. + +// This variable will be important to get the specific fields within the record. +rec = zoho.crm.getRecordById({module},{argumentId}); + +// These variables are used to simplify getting field information +name = rec.get("First_Name") + " " + rec.get("Last_Name"); +totalWattage = rec.get("Wattage_Per_Panel") * rec.get("Number_of_Panels"); + +// A temporary map is created to store the data from the original record. +mp = Map(); + +// This if-statement verifies that the user has paid using a field. If the field is selected, it will return true and will +// allow you to convert the record. However, if the field is not selected it will give you an error. + +if(rec.get("Has_Paid") == true) +{ + // These statements follow the format mp.put({fieldInNewModule}, {fieldInOriginalModule}); + // For example in the instructions below, the statement will put the value name from line 7 + // into the keyword "Name". These keys are stored into the map and will then be used to create + // the record in line 37. + + mp.put("Name",name); + mp.put("Email",rec.get("Email")); + mp.put("First_Name",rec.get("First_Name")); + mp.put("Last_Name",rec.get("Last_Name")); + mp.put("Phone",rec.get("Phone")); + mp.put("Mobile",rec.get("Mobile")); + mp.put("Email",rec.get("Email")); + mp.put("Installation_Address",rec.get("Installation_Address")); + mp.put("Installation_City",rec.get("Installation_City")); + mp.put("Installation_State",rec.get("Installation_State")); + mp.put("Installation_Zip_Code",rec.get("Installation_Zip_Code")); + mp.put("Number_of_Panels",rec.get("Number_of_Panels")); + mp.put("Wattage_Per_Panel",rec.get("Wattage_Per_Panel")); + mp.put("Installation_Zip_Code",rec.get("Installation_Zip_Code")); + mp.put("Total_Wattage",totalWattage.toString()); + createClient = zoho.crm.createRecord("Clients",mp); + result = "Success!"; + + // If you would like to delete the record after it is converted you can uncomment out lines 43-45 by + // removing the double forward slash. + //Delete Record + //deleteRecordMap = Map(); + //deleteRecordMap = {"module":"{module}","id":argumentId}; + //deleteResp = zoho.crm.invokeConnector("crm.delete",deleteRecordMap); +} +else +{ + result = "ERROR: Prospect has not paid or \"Has Paid\" field hasn't been updated. Please verify these requirements have been met."; +} +return result; diff --git a/Deluge Functions/Custom Functions/Capturing_Sales_Region.ds b/Deluge Functions/Custom Functions/Capturing_Sales_Region.ds new file mode 100644 index 0000000..aa962f4 --- /dev/null +++ b/Deluge Functions/Custom Functions/Capturing_Sales_Region.ds @@ -0,0 +1,29 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: georgeotj +// Description: Based on a Lead's country, they will be marked to a specific region in their profile. +// Requirements: Custom field called "Region" in the Leads module inside the Address Information +// Arguments: leadId: Lead Id, country: Country, fieldToUpdate: Region + +// Declare variables +countryList1 = {"united kingdom","uk","great britain","gb"}; +countryList2 = {"united states","usa","us"}; +countryList3 = {"argentina","bolivia","brazil","chile","colombia","ecuadar","guiana","guyana","mexico","paraguay"}; +countryList4 = {"France","Belgium","Germany","Netherlands","Ireland","Israel","South Africa","Italy","United Arab Emirates","Spain"}; +countryList5 = {"Singapore","China","Japan","Thailand","Vietnam","Malaysia","Mauritius","Hongkong","Maldives","Pakistan"}; +countryMap = {"UK":countryList1,"US":countryList2,"SAMERICA":countryList3,"EMEA":countryList4,"APAC":countryList5}; + +countryMapkKey = countryMap.keys(); +mailingRegion = ""; + +// Code +for each region in countryMapkKey +{ + countryListValue = countryMap.get(region); + if(countryListValue.contains(country.toLowerCase())) + { + mailingRegion = region; + } +} +updateMap = {fieldToUpdate:mailingRegion}; +updatedResponse = zoho.crm.updateRecord("Leads",leadId,updateMap); diff --git a/Deluge Functions/Custom Functions/Close_Junk_Lead_Tasks.ds b/Deluge Functions/Custom Functions/Close_Junk_Lead_Tasks.ds new file mode 100644 index 0000000..525ac02 --- /dev/null +++ b/Deluge Functions/Custom Functions/Close_Junk_Lead_Tasks.ds @@ -0,0 +1,19 @@ +// Author: georgeotj +// Description: There are many sources for lead generation within Zoho CRM. When you validate the leads during the nurturing process, a few leads will qualify as Junk. Even if you mark a lead as junk, the tasks associated with it will remain open. This function allows you to close tasks associated with junk leads. +// Requirements: No changes necessary for CRM. +// Arguments: LeadID: Lead Id, status: Lead Status + +// Declare variables + +// Code +if(leadStatus.contains("Junk")) +{ + relatedTask = zoho.crm.getRelatedRecords("Tasks","Leads",leadId); + for each task in relatedTask + { + mapVariable = Map(); + mapVariable.put("Status","Completed"); + taskID = task.get("id"); + updateTask = zoho.crm.updateRecord("Tasks",taskID,mapVariable); + } +} diff --git a/Deluge Functions/Custom Buttons/convert_lead_from_quote_view.ds b/Deluge Functions/Custom Functions/Convert_Lead_From_Quote_View.ds similarity index 96% rename from Deluge Functions/Custom Buttons/convert_lead_from_quote_view.ds rename to Deluge Functions/Custom Functions/Convert_Lead_From_Quote_View.ds index a6aa0fe..23860e7 100644 --- a/Deluge Functions/Custom Buttons/convert_lead_from_quote_view.ds +++ b/Deluge Functions/Custom Functions/Convert_Lead_From_Quote_View.ds @@ -26,4 +26,4 @@ quote_map.put("Contact_Name",contact_ID); // Update Quote with Account / Contact ID resp = zoho.crm.updateRecord("Quotes",quote_ID,quote_map); -return "Success: Lead Converted"; \ No newline at end of file +return "Success: Lead Converted"; diff --git a/Deluge Functions/Custom Functions/Convert_Lead_To_Prospect.ds b/Deluge Functions/Custom Functions/Convert_Lead_To_Prospect.ds new file mode 100644 index 0000000..01f17d3 --- /dev/null +++ b/Deluge Functions/Custom Functions/Convert_Lead_To_Prospect.ds @@ -0,0 +1,21 @@ +//Arguments: leadId = Lead ID +rec = zoho.crm.getRecordById("Leads1",leadId); +mp = Map(); +// Get data from the Prospect record and make a Lead record +mp.put("First_Name",rec.get("First_Name")); +mp.put("Last_Name",rec.get("Last_Name")); +mp.put("Email",rec.get("Email")); +if(rec.get("Phone_Type") == "Mobile") +{ + mp.put("Mobile",rec.get("Phone")); +} +else +{ + mp.put("Phone",rec.get("Phone")); +} +createProspect = zoho.crm.createRecord("Leads",mp); +// Delete Prospect record +//deleteRecordMap = Map(); +//deleteRecordMap = {"module":"Leads1","id":leadId}; +//deleteResp = zoho.crm.invokeConnector("crm.delete",deleteRecordMap); +return rec; diff --git a/Deluge Functions/Custom Functions/Create_CF_History_Record.ds b/Deluge Functions/Custom Functions/Create_CF_History_Record.ds new file mode 100644 index 0000000..5330cfa --- /dev/null +++ b/Deluge Functions/Custom Functions/Create_CF_History_Record.ds @@ -0,0 +1,40 @@ +// Author: georgeotj +// Description: This script will allow you to create a new record to keep a history of the changes made to a specific custom field +// Requirements: Associated Module is Dealsd, Custom Module with fields Name (Single Line), Owner (Lookup), Updated From (Single Line), Updated To (Single line), Deal Associated (Lookup, Deals) +// Arguments: dealId Deal Id + +// Declare variables +related = zoho.crm.getRelatedRecords("CF_Updated_History","Deals",dealId); +deal = zoho.crm.getRecordById("Deals",dealId); +currentClose = deal.get("Expected_Close_Date"); +previousClose = deal.get("Previous_Close_Date"); +dealName = deal.get("Deal_Name"); +lastModified = deal.get("Modified_By"); + +//Code +// Try to create the lastEntry variable but if there's nothing available set it to today. +try +{ + lastEntry = related.get(0).get("Created_Time"); +} + catch (e) +{ lastEntry = today.toDate(); +} +timeDif = days360(lastEntry,today); + +//Create the record +if(currentClose != previousClose) +{ + mp = Map(); + mp.put("Updated_To",currentClose); + mp.put("Updated_From",previousClose); + mp.put("Deal_Associated",dealId); + mp.put("Name",dealName); + mp.put("Owner",lastModified); + mp.put("Days_Between_Changes",timeDif.toString()); + createRec = zoho.crm.createRecord("Deal_CF_History",mp); + // Update fields in Deals Module + updatePrevMap = Map(); + updatePrevMap.put("Previous_Close_Date",currentClose); + updatePrevious = zoho.crm.updateRecord("Deals",dealId,updatePrevMap); +} diff --git a/Deluge Functions/Custom Functions/Create_Projects_While_Winning_Potentials.ds b/Deluge Functions/Custom Functions/Create_Projects_While_Winning_Potentials.ds new file mode 100644 index 0000000..b5ce4cb --- /dev/null +++ b/Deluge Functions/Custom Functions/Create_Projects_While_Winning_Potentials.ds @@ -0,0 +1,22 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: Zach Zivnuska +// Description: This function will automatically create a new Project whenever a deal is created. +// Requirements: Must have an active Zoho Projects account +// Arguments: N/A +// Notes: //In order to get your URL, you must replace the [portalId] with your organization's + //To get your portalId, follow the instructions below + //Go to Zoho Projects --> go to Setup --> Under 'Integration' click "Developer Space" in the page that opens, + //click on "Service Hooks" --> look at the URL's and you will see your organization's portalId. + +// Declare variables +m = {"name":name}; + +// Code +response = invokeurl +[ + url :"https://projectsapi.zoho.com/restapi/portal/[portalId]/projects/" + type :POST + parameters:m + connection:"zoho264" +]; diff --git a/Deluge Functions/Custom Functions/Creating_Sales_Order_For_Zoho_Books_From_Zoho_CRM.ds b/Deluge Functions/Custom Functions/Creating_Sales_Order_For_Zoho_Books_From_Zoho_CRM.ds new file mode 100644 index 0000000..a4c9eb6 --- /dev/null +++ b/Deluge Functions/Custom Functions/Creating_Sales_Order_For_Zoho_Books_From_Zoho_CRM.ds @@ -0,0 +1,25 @@ +sOrderObj = zoho.crm.getRecordById("Sales_Orders", id); +crmSOProductLst = sOrderObj.get("Product_Details"); +crmContactId = ifnull(sOrderObj.get("Contact_Name"),{"id", null}).get("id"); +crmAccountId = ifnull(sOrderObj.get("Account_Name"),{"id", null}).get("id"); +prodList=List(); +for each product in crmSOProductLst +{ + pId = product.get("product").get("id"); + quantity = product.get("quantity"); + listPrice = product.get("list_price").toDecimal(); + zbPId = zoho.books.getRecords("Items", "668072369","zcrm_product_id="+pId).get("items").get(0).get("item_id"); + prodmp = map(); + prodmp.put("item_id",zbPId); + prodmp.put("rate",listPrice); + prodmp.put("quantity",quantity); + prodList.add(prodmp); +} +customerid = zoho.books.getRecords("Contacts", "668072369","zcrm_account_id="+crmAccountId).get("contacts").get(0).get("contact_id"); +mp = map(); +mp.put("customer_id",customerid); +mp.put("line_items",prodList); +mp.put("date",today); +mp.put("custom_fields", [{"label": "Third Party Cleaned", "value": sOrderObj.get(“Cleaned_By_Joe”)},{"label":"Con Note No", "value": sOrderObj.get(“Consignment_Note_Number”)},{“label":"DATE INVOICE SENT", "value": sOrderObj.get(“DATE_INVOICE_SENT”)},{“label":"Delivery Terms", "value": sOrderObj.get(“Delivery_Terms”)},{“label":"Shipment Date", "value": sOrderObj.get(“Ready_For_Despatch_Date”)},{“label":"Freight Company", "value": sOrderObj.get(“Freight_Company_Out”)},{“label":"Freight Company", "value": sOrderObj.get(“Freight_Company_Out”)},{“label":"Payment Received Date", "value": sOrderObj.get(“Payment_Received_Date”)},{“label":"PO Received Date", "value": sOrderObj.get(“PO_Received_Date”)},{“label":"Sales Order#", "value": sOrderObj.get(“Project_Quote_Number”)},{“label":"PO Number", "value": sOrderObj.get(“Purchase_Order”)},{“label":"Quote Category", "value": sOrderObj.get(“Quote_Category”)},{“label":"Sales Order Type", "value": sOrderObj.get(“Sales_Order_Type”)},{“label":"Status", "value": sOrderObj.get(“Status”)},{“label":"Subject", "value": sOrderObj.get(“Subject”)}]); +createSoInZBRes = zoho.books.createRecord("SalesOrders","668072369", mp); +info createSoInZBRes; diff --git a/Deluge Functions/Custom Functions/Current_Value_In_Previous.ds b/Deluge Functions/Custom Functions/Current_Value_In_Previous.ds new file mode 100644 index 0000000..888a122 --- /dev/null +++ b/Deluge Functions/Custom Functions/Current_Value_In_Previous.ds @@ -0,0 +1,15 @@ +// Author: georgeotj +// Description: To be able to keep a history of status changes, we must ensure that we still keep the previous choice. This will work with a Workflow that will only run when new deals are created. +// Requirements: In the deals module, you must create 2 Custom Fields that will store the current and the previouas status'. +// Arguments: dealId = Deal Id + +// Declare variables +deal = zoho.crm.getRecordById("Deals",dealId); + +//Code +currentClosing = deal.get("Expected_Close_Date"); +previousClosing = deal.get("Previous_Close_Date"); +mp = Map(); +mp.put("Previous_Close_Date",deal.get("Expected_Close_Date")); +updateResp = zoho.crm.updateRecord("Deals",dealId,mp); +info updateResp; diff --git a/Deluge Functions/Custom Functions/Generate_Total_Revenue_From_Deals b/Deluge Functions/Custom Functions/Generate_Total_Revenue_From_Deals new file mode 100644 index 0000000..9a59083 --- /dev/null +++ b/Deluge Functions/Custom Functions/Generate_Total_Revenue_From_Deals @@ -0,0 +1,24 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: georgeotj +// Description: This function will track total revenue by adding up all the deals +// Requirements: This will require a custom field in the "Accounts" module, it will be called Total Revenue. +// Arguments: accountId:Account Id, Total_Revenue:Total Revenue + +// Declare variables +accountID1 = accountId.toString(); +resp = zoho.crm.getRelatedRecords("Deals","Accounts",accountId); +total = 0.0; + +// Code +for each rec in resp +{ + stage = rec.get("Stage").toLowerCase(); + if(stage.contains("won")) + { + total = total + rec.get("Amount").toDecimal(); + info total; + updateResp = zoho.crm.updateRecord("Accounts",accountId,{"Total_Revenue":total}); + info updateResp; + } +} diff --git a/Deluge Functions/Custom Functions/Lead_Scoring.ds b/Deluge Functions/Custom Functions/Lead_Scoring.ds new file mode 100644 index 0000000..4e417d8 --- /dev/null +++ b/Deluge Functions/Custom Functions/Lead_Scoring.ds @@ -0,0 +1,70 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: georgeotj +// Description: To rate leads, we want to follow certain criteria like having a phone numberm, email, and more information. +// Requirements: Leads module with a custom text field called, "LeadScore" +// Arguments: leadId:Lead Id, phone:Phone, email:Email, title:Title, website:Website, industry:Industry, scoreField:LeadScore + +// Declare variables + + +// Code +//Verify that if the fields are null (different from isEmpty()) +if(phone.isNull()) { + phone = ""; +} +if(email.isNull()) { + email = ""; +} +if(title.isNull()) { + title = ""; +} +if(website.isNull()) { + website = ""; +} +if(industry.isNull()){ + industry = ""; +} +if(scoreField.isNull() || scoreField.isEmpty()) { + scoreField = ""; +} + +//Start counting up the points +point = 0; + +if(phone.length() >= 9) { + point += 2; +} +if(!(email.contains("gmail") || email.contains("yahoo") || email.contains("outlook") || email == "")) { + point += 2; +} +if(title.contains("CEO") || title.contains("manager") || title.contains("dir") || title.contains("VP")) { + point += 2; +} +if(!website.isBlank()) { + point += 2; +} +if(industry.contains("ERP")) { + point += 2; +} + +//Calculating the points. +if(point >= 9) { + score = "*****"; +} +else if(point >= 7) { + score = "****"; +} +else if(point >= 5) { + score = "***"; +} +else if(point >= 3) { + score = "**"; +} +else if(point >= 1) { + score = "*"; +} +else { + score = ""; +} +updatedResponse = zoho.crm.updateRecord("Leads",leadId,{"LeadScore":score}); diff --git a/Deluge Functions/Custom Functions/Mass_Update_of_Child_Contacts.ds b/Deluge Functions/Custom Functions/Mass_Update_of_Child_Contacts.ds new file mode 100644 index 0000000..78ff06e --- /dev/null +++ b/Deluge Functions/Custom Functions/Mass_Update_of_Child_Contacts.ds @@ -0,0 +1,26 @@ +// Author: georgeotj +// Description: Automatically updates the address of child contacts whenever the address information for the Account is updated. +// Requirements: N/A +// Arguments: accID = Account Id + +// Declare variables +rec = zoho.crm.getRecordById("Accounts",accId); +resp = zoho.crm.getRelatedRecords("Contacts","Accounts",accId); + +// Code +for each ele in resp +{ + mp = Map(); + mp.put("Mailing_Street",rec.get("Billing_Street")); + mp.put("Mailing_City",rec.get("Billing_City")); + mp.put("Mailing_State",rec.get("Billing_State")); + mp.put("Mailing_Zip",rec.get("Billing_Code")); + mp.put("Mailing_Country",rec.get("Billing_Country")); + mp.put("Other_Street",rec.get("Shipping_Street")); + mp.put("Other_City",rec.get("Shipping_City")); + mp.put("Other_State",rec.get("Shipping_State")); + mp.put("Other_Zip",rec.get("Shipping_Code")); + mp.put("Other_Country",rec.get("Shipping_Country")); + contactId = ele.get("id"); + updateResp = zoho.crm.updateRecord("Contacts",ele.get("id"),mp); +} diff --git a/Deluge Functions/Custom Functions/README.txt b/Deluge Functions/Custom Functions/README.txt new file mode 100644 index 0000000..014d81a --- /dev/null +++ b/Deluge Functions/Custom Functions/README.txt @@ -0,0 +1,10 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: +// Description: +// Requirements: +// Arguments: + +// Declare variables + +// Code diff --git a/Deluge Functions/Custom Functions/Show_Related_Addresses_Of_Account.ds b/Deluge Functions/Custom Functions/Show_Related_Addresses_Of_Account.ds new file mode 100644 index 0000000..1d1adaf --- /dev/null +++ b/Deluge Functions/Custom Functions/Show_Related_Addresses_Of_Account.ds @@ -0,0 +1,15 @@ +// Author: georgeotj +// Description: When your CRM has a lot of customers with different shipping addresses, managing them could become a pain. Using this, a user can create a Zoho Creator application that will allow the user to modify a Creator form that would easily change the shipping address depending on which Account the user selects. +// Requirements: Several modifications are required for this script to run correctly, this includes creating a new module and related list. +// Arguments: N/A + +// Declare variables +accountId = input.Account_Name.toLong(); +relRecs = zoho.crm.getRelatedRecords("Associated_Shipping_Location","Accounts",accountId); + +// Code +clear Shipping_Address; +for each rec in relRecs +{ + input.Shipping_Address:ui.add(rec.get("Name")); +} diff --git a/Deluge Functions/Custom Functions/Take_Current_CF_Add_To_Previous_CF.ds b/Deluge Functions/Custom Functions/Take_Current_CF_Add_To_Previous_CF.ds new file mode 100644 index 0000000..2c3a164 --- /dev/null +++ b/Deluge Functions/Custom Functions/Take_Current_CF_Add_To_Previous_CF.ds @@ -0,0 +1,15 @@ +// Author: goergeotj +// Description: To keep track of history of the changes to a specific field, we must preserve the original value. +// Requirements: Associated Mod8ule is Deal also, 2 Custom Fields, in this case "Expected_Close_Date" and "Previous_Close_Date" within the Deals module +// Arguments: dealId = Deal Id + +// Declare variables +deal = zoho.crm.getRecordById("Deals",dealId); +currentClosing = deal.get("Expected_Close_Date"); +previousClosing = deal.get("Previous_Close_Date"); + +// Code +mp = Map(); +mp.put("Previous_Close_Date",deal.get("Expected_Close_Date")); +updateResp = zoho.crm.updateRecord("Deals",dealId,mp); +info updateResp; diff --git a/Deluge Functions/Custom Functions/Time_To_Close.ds b/Deluge Functions/Custom Functions/Time_To_Close.ds new file mode 100644 index 0000000..b87849c --- /dev/null +++ b/Deluge Functions/Custom Functions/Time_To_Close.ds @@ -0,0 +1,23 @@ +This folder will contain custom functions for Zoho CRM. These functions will have the following format + +// Author: Zach Zivnuska/georgeotj +// Description: This function will calculate how many hours it took to close. +// Requirements: N/A +// Arguments: leadId:Lead Id + +// Declare variables +related = zoho.crm.getRelatedRecords("Activities_History","Leads",leadId); +lead = zoho.crm.getRecordById("Leads",leadId); + +// Code +for each rec in related +{ + ctn = rec.get("Closed_Time"); +} +created = lead.get("Created_Time"); +closedTime = ctn.toDateTime("yyyy-MM-dd'T'HH:mm:ss"); +openedTime = created.toDateTime("yyyy-MM-dd'T'HH:mm:ss"); +tot = (closedTime - openedTime) / (1000 * 3600); +info openedTime; +info closedTime; +info tot; diff --git a/Deluge Functions/Custom Functions/Total_Cost_of_Tradeshow.ds b/Deluge Functions/Custom Functions/Total_Cost_of_Tradeshow.ds new file mode 100644 index 0000000..f38fa66 --- /dev/null +++ b/Deluge Functions/Custom Functions/Total_Cost_of_Tradeshow.ds @@ -0,0 +1,19 @@ +// Author: georgeotj +// Description: This deluge script will pull entries from the Expenses modules and when attributed to a campaign, will add up the expenses to the "Actual Cost" field in the Campaign entry. +// Requirements: "Trade Show Expenses" module +// Arguments: expid = Trade Show Expense id, campid = Campaign id + +// Declare variables +relexp = zoho.crm.getRecordById("Trade_Show_Expenses",expid); +newrel = zoho.crm.getRelatedRecords("Expenses","Campaigns",campid); +total = 0.0; + +//Total up all expenses related to the Campaign +for each rec in newrel +{ + //iterate and refresh total in case other expense amounts change at later date + total = total + if(rec.get("Amount") == "",0.0,rec.get("Amount").toDecimal()); +} + +//Update Campaign with new values +update = zoho.crm.updateRecord("Campaigns",campid,{"Actual_Cost":total}); diff --git a/Deluge Functions/Custom Functions/Trade_Show_ROI.ds b/Deluge Functions/Custom Functions/Trade_Show_ROI.ds new file mode 100644 index 0000000..5aa8495 --- /dev/null +++ b/Deluge Functions/Custom Functions/Trade_Show_ROI.ds @@ -0,0 +1,23 @@ +// Author: georgeotj +// Description: This deluge script will auomatically calculate the ROI of a Campaign when comparing Actual Revenue and Actual Cost +// Requirements: Revenue Information for +// Arguments: campid = Campaign id, dealid = Deal Id + +// Declare variables +deal = dealid; +thisCampaign = zoho.crm.getRecordById("Campaigns",campid); +relatedDeals = zoho.crm.getRelatedRecords("Deals","Campaigns",campid); +total = 0.0; + +// Look through the Deals related list in the Campaigns module and if there's a "Closed Won" deal, add it up to the Actual Revenue +for each deal in relatedDeals +{ + info deal.get("Amount"); + stage = deal.get("Stage"); + info stage; + if(stage == "Closed Won") + { + total = total + ifnull(deal.get("Amount"),"0.0").toDecimal(); + } + update = zoho.crm.updateRecord("Campaigns",campid,{"Actual_Revenue":total}); +} diff --git a/Deluge Functions/Custom Functions/iterate_through_multiselect_lookupfield.ds b/Deluge Functions/Custom Functions/iterate_through_multiselect_lookupfield.ds new file mode 100644 index 0000000..1861103 --- /dev/null +++ b/Deluge Functions/Custom Functions/iterate_through_multiselect_lookupfield.ds @@ -0,0 +1,23 @@ + +serverList = zoho.crm.getRelatedRecords("Servers13","Contacts",contid); +listcount = 1; +counter = {0,1,2,3,4,5,6,7,8,9,10}; +listSize = serverList.size(); +for each x in counter +{ + count = x + 1; + if(x < listSize) + { + server = serverList.get(x); + serverInfo = server.get("Servers"); + serverid = serverInfo.get("id"); + url = "https://crm.zoho.com/crm/org672017945/tab/CustomModule1/" + serverid; + update = zoho.crm.updateRecord("Contacts",contid,{"Server" + count:url}); + listcount = listcount + 1; + } + else + { + update = zoho.crm.updateRecord("Contacts",contid,{"Server" + count:""}); + info "removed"; + } +} diff --git a/Python/Zoho_CRM_API/2.0/Authentication/credentials.py-example b/Python/Zoho_CRM_API/2.0/Authentication/credentials.py-example index 6b56143..8f09028 100644 --- a/Python/Zoho_CRM_API/2.0/Authentication/credentials.py-example +++ b/Python/Zoho_CRM_API/2.0/Authentication/credentials.py-example @@ -1,7 +1,5 @@ -__author__ = 'MinterS' - # User Credentials from Zoho CRM redirect_uri = 'http://www.mysite.com/success.php' client_id = '####.####################' client_secret = '#############################' -access_type = 'offline' \ No newline at end of file +access_type = 'offline' diff --git a/Python/Zoho_CRM_API/2.0/Authentication/tokens.py b/Python/Zoho_CRM_API/2.0/Authentication/tokens.py index 5356b34..ff54531 100644 --- a/Python/Zoho_CRM_API/2.0/Authentication/tokens.py +++ b/Python/Zoho_CRM_API/2.0/Authentication/tokens.py @@ -2,16 +2,11 @@ import os - - # Token Files THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) grantTokenFile = os.path.join(THIS_FOLDER, 'grant_token.txt') accessTokenFile = os.path.join(THIS_FOLDER, 'access_token.txt') refreshTokenFile = os.path.join(THIS_FOLDER, 'refresh_token.txt') -# grantTokenFile = '2.0/Authentication/grant_token.txt' -# accessTokenFile = '2.0/Authentication/access_token.txt' -# refreshTokenFile = '2.0/Authentication/refresh_token.txt' # Save access token to file def saveAccess (token): @@ -46,4 +41,4 @@ def getRefresh (): token = f.readline() f.close() refreshToken = token - return refreshToken \ No newline at end of file + return refreshToken diff --git a/Python/Zoho_CRM_API/2.0/getAuthRefresh.py b/Python/Zoho_CRM_API/2.0/getAuthRefresh.py index 78de645..aba2558 100644 --- a/Python/Zoho_CRM_API/2.0/getAuthRefresh.py +++ b/Python/Zoho_CRM_API/2.0/getAuthRefresh.py @@ -9,7 +9,6 @@ import requests import json - def getAuthRefresh(): # Collect Refresh Token and Build URL url = 'https://accounts.zoho.com/oauth/v2/token?refresh_token={refresh_token}&client_id={client_id}&client_secret={client_secret}&grant_type=refresh_token' @@ -50,5 +49,4 @@ def getAuthRefresh(): # Write Token to File tokens.saveAccess(access) - token = getAuthRefresh() diff --git a/Python/Zoho_CRM_API/2.0/insertTasksMockaroo.py b/Python/Zoho_CRM_API/2.0/insertTasksMockaroo.py new file mode 100644 index 0000000..8007719 --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/insertTasksMockaroo.py @@ -0,0 +1,49 @@ +__author__ = 'JorgeH' + +import requests +import json +import urllib.request +from Authentication import tokens + +# Define URL +# The key that appears on the Mockaroo URL at the end must match the API key of the user # noqa +url = 'https://www.zohoapis.com/crm/v2/tasks' + +# NOTE: User must add the URL of the API they created in Mockaroo +urlMockaroo = '' + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through. Currently working on this. +body = { + "data": [ + mockData[0], mockData[1], mockData[2], mockData[3], mockData[4] + ] +} + +# Print Input Data +print('') +print('---- Request ----') +print('URL:', url) +print('Head:', headers) + +# Call API +response = requests.post(url, headers=headers, json=body) + +# Print Output Data +if (response.status_code) == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print('') + print('-- Response --') + print(json.dumps(data, sort_keys=True, indent=4)) +else: + print(response.status_code) + print(response.text) diff --git a/Python/Zoho_CRM_API/2.0/upsertAccountsMockaroo.py b/Python/Zoho_CRM_API/2.0/upsertAccountsMockaroo.py new file mode 100644 index 0000000..3239017 --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/upsertAccountsMockaroo.py @@ -0,0 +1,48 @@ +__author__ = 'JorgeH' + +import requests +import json +import urllib.request +from Authentication import tokens + +# Define URL +url = 'https://www.zohoapis.com/crm/v2/Accounts/upsert' + +# NOTE: User must add the URL of the API they created in Mockaroo +urlMockaroo = '' + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through. Currently working on this. +body = { + "data": [ + mockData[0] + ] +} + +# Print Input Data +print('') +print('---- Request ----') +print('URL:', url) +print('Head:', headers) + +# Call API +response = requests.post(url, headers=headers, json=body) + +# Print Output Data +if (response.status_code) == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print('') + print('-- Response --') + print(json.dumps(data, sort_keys=True, indent=4)) +else: + print(response.status_code) + print(response.text) diff --git a/Python/Zoho_CRM_API/2.0/upsertContactsMockaroo.py b/Python/Zoho_CRM_API/2.0/upsertContactsMockaroo.py new file mode 100644 index 0000000..ee0fda9 --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/upsertContactsMockaroo.py @@ -0,0 +1,48 @@ +__author__ = 'JorgeH' + +import requests +import json +import urllib.request +from Authentication import tokens + +# Define URL +url = 'https://www.zohoapis.com/crm/v2/Contacts/upsert' + +# NOTE: User must add the URL of the API they created in Mockaroo +urlMockaroo = '' + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through. Currently working on this. +body = { + "data": [ + mockData[0] + ] +} + +# Print Input Data +print('') +print('---- Request ----') +print('URL:', url) +print('Head:', headers) + +# Call API +response = requests.post(url, headers=headers, json=body) + +# Print Output Data +if (response.status_code) == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print('') + print('-- Response --') + print(json.dumps(data, sort_keys=True, indent=4)) +else: + print(response.status_code) + print(response.text) diff --git a/Python/Zoho_CRM_API/2.0/upsertDealsMockaroo.py b/Python/Zoho_CRM_API/2.0/upsertDealsMockaroo.py new file mode 100644 index 0000000..1767232 --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/upsertDealsMockaroo.py @@ -0,0 +1,48 @@ +__author__ = 'JorgeH' + +import requests +import json +import urllib.request +from Authentication import tokens + +# Define URL +url = 'https://www.zohoapis.com/crm/v2/Deals/upsert' + +# NOTE: User must add the URL of the API they created in Mockaroo +urlMockaroo = '' + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through. Currently working on this. +body = { + "data": [ + mockData[0], mockData[1], mockData[2], mockData[3], mockData[4] + ] +} + +# Print Input Data +print('') +print('---- Request ----') +print('URL:', url) +print('Head:', headers) + +# Call API +response = requests.post(url, headers=headers, json=body) + +# Print Output Data +if (response.status_code) == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print('') + print('-- Response --') + print(json.dumps(data, sort_keys=True, indent=4)) +else: + print(response.status_code) + print(response.text) diff --git a/Python/Zoho_CRM_API/2.0/upsertLeadsMockaroo.py b/Python/Zoho_CRM_API/2.0/upsertLeadsMockaroo.py new file mode 100644 index 0000000..427138d --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/upsertLeadsMockaroo.py @@ -0,0 +1,46 @@ +__author__ = 'JorgeH' + +import requests +import json +import urllib.request +from Authentication import tokens + +# Define URL +url = 'https://www.zohoapis.com/crm/v2/Leads/upsert' + +# NOTE: User must add the URL of the API they created in Mockaroo +urlMockaroo = '' + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through. Currently working on this. +body = { + "data": [ + mockData[0], mockData[1], mockData[2] + ] +} + +# Print Input Data +print(' \n ---- Request ----') +print('URL:', url) +print('Head:', headers) + +# Call API +response = requests.post(url, headers=headers, json=body) + +# Print Output Data +if (response.status_code) == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print(' \n ---- Response ----') + print(json.dumps(data, sort_keys=True, indent=4)) +else: + print(response.status_code) + print(response.text) diff --git a/Python/Zoho_CRM_API/2.0/upsertSetMockaroo.py b/Python/Zoho_CRM_API/2.0/upsertSetMockaroo.py new file mode 100644 index 0000000..17ca629 --- /dev/null +++ b/Python/Zoho_CRM_API/2.0/upsertSetMockaroo.py @@ -0,0 +1,63 @@ +import requests, json, urllib.request +import getAuthRefresh +from Authentication import tokens + +# Necessary URLs +url ='https://www.zohoapis.com/crm/v2/{module}/upsert' +urlMockaroo ='' + + +def upsertRecords(url, headers, body, getAuthRefresh): + # Print Input Data + print('\n---- Request ----') + print('URL: ', url) + print('Head: ', headers) + + # Call API + response = requests.post(url, headers=headers, json=body) + + # Print Output Data + if response.status_code == 200: + jsonData = json.loads(response.text) + data = jsonData['data'] + print(' \n ---- Response ----') + print(json.dumps(data, sort_keys=True, indent=4)) + elif response.status_code == 401: + print(response.status_code) + print(response.text) + runAgain = getAuthRefresh + else: + print(response.status_code) + print(response.text) + +# Reads the Mockaroo data and loads it into the file +data = urllib.request.urlopen(urlMockaroo).read() +mockData = json.loads(data) + +# Get Token and Headers +token = tokens.getAccess() +headers = {'Authorization': token} + +# Build Body +# NOTE: The mockData[x] must be iterated through, still haven't been able to figure it out. +body = { + "data": [ + mockData[0], mockData[1], mockData[2], mockData[3] + ] +} + +url = url.replace('{module}', 'Properties') +upsertRecords(url, headers, body, getAuthRefresh) +url = url.replace('Properties', '{module}') + +# #Add the layout number to the +url = url.replace('{module}', 'Accounts') +upsertRecords(url, headers, body, getAuthRefresh) +url = url.replace('Accounts', '{module}') + +url = url.replace('{module}', 'Contacts') +upsertRecords(url, headers, body, getAuthRefresh) +url = url.replace('Contacts', '{module}') + +url = url.replace('{module}', 'Deals') +upsertRecords(url, headers, body, getAuthRefresh) diff --git a/README.md b/README.md index ed25398..948d4a7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Author: - Scott Minter + Scott Minter/Jorge Huerta ### Project Outline and Goals: