An article so that I don't spend so long in trying to find sales persons in Zoho Books.
Why?
My use case is that I want to create a Sales Order in ZohoBooks based on one in ZohoCRM and wanted to assign the sales person.
How?
So after an hour or so trying to get the Zoho.books.getRecords() function to filter the sales persons, I gave up and used a for each loop instead.
In the next snippet of code, I am getting the Zoho CRM record owner, looping through all salespersons in Zoho Books, and retrieving the salesperson_id. Also I have a connector to ZohoBooks called "joel_books". The "v_Filter" appears to do absolutely nothing but I've left it in there in case one day I figure it out:
// init m_CreateSO = Map(); v_SalesPersonID = ""; // // eval v_BooksOrgID = 12345678901; r_SoDetails = zoho.crm.getRecordById("Sales_Orders",p_SoID); // // check if owner and get matching salesperson ID if(!isnull(r_SoDetails.get("Owner"))) { v_OwnerID = r_SoDetails.get("Owner").get("id"); v_Filter = "crm_reference_id=" + v_OwnerID; l_AllSalesPersons = zoho.books.getRecords("salespersons", v_BooksOrgID, v_Filter, "joel_books"); for each r_SalesPerson in l_AllSalesPersons { if(r_SalesPerson.get("crm_reference_id") == v_OwnerID) { v_SalesPersonID = r_SalesPerson.get("salesperson_id"); break; } } m_CreateSO.put("salesperson_id",v_SalesPersonID); }
- // init
- m_CreateSO = Map();
- v_SalesPersonID = "";
- //
- // eval
- v_BooksOrgID = 12345678901;
- r_SoDetails = zoho.crm.getRecordById("Sales_Orders",p_SoID);
- //
- // check if owner and get matching salesperson ID
- if(!isnull(r_SoDetails.get("Owner")))
- {
- v_OwnerID = r_SoDetails.get("Owner").get("id");
- v_Filter = "crm_reference_id=" + v_OwnerID;
- l_AllSalesPersons = zoho.books.getRecords("salespersons", v_BooksOrgID, v_Filter, "joel_books");
- for each r_SalesPerson in l_AllSalesPersons
- {
- if(r_SalesPerson.get("crm_reference_id") == v_OwnerID)
- {
- v_SalesPersonID = r_SalesPerson.get("salesperson_id");
- break;
- }
- }
- m_CreateSO.put("salesperson_id",v_SalesPersonID);
- }
Additional Note(s):
- Scope(s) required: for the connection I think it was ZohoBooks.settings.READ for the sales persons and then ZohoCRM.modules.all for the CRM sales orders.