I hate to be a bother to the fine folks here, but I'm stuck in another function. GOAL: write a custom function to count the number of Meetings each person in Contacts has for the current month, then push that count to a field in the contact record.
Spent about 6 hours trying different versions of the function, none work. Original code below. I think I might have to use CoQL query for the function, but was hoping to avoid it. Never used APIs.
Attempts so far: Tried to iterate in various forms & found out Deluge doesn't support iterative loops with increments. Found out CRM deluge doesn't support count() for a collection, it's only applicable to Creator according to help docs. And the integration task "zoho.crm.searchrecords" only supports equals and starts with as criteria, so I can't search "in" the current month.
Then I thought about using intersect(). But now currently thinking, in natural language: "for each name in Contacts, select query search Meetings this month where Event_Title contains name" and return count of record, I assume using size().
So, maybe I need to use a "for each" loop on Contacts with a CoQL select query for meetings in the current month where the Event_Title field contains the contact's name.
Really frustrating as a non-dev. I'm sure there's multiple ways to do it but I can't figure it out due to search criteria limitations. Makes me feel stupid, and it feels like there's information missing from the help documents.
Original Code (trying to iterate, mistakes and all):
- Startdate = zoho.currentdate.toStartOfMonth();
- Enddate = Startdate.addMonth(1);
- eventlist = zoho.crm.searchRecords("Events","Start_DateTime : in : this month");
- myList = eventlist.toList();
- for each rec in clients
- {
- name = rec.getJSON("Last_Name");
- ident = rec.getJSON("id");
- sessioncount = 0;
- for each meeting in myList
- {
- title = meeting.getJSON("Event_Title");
- if(title.contains(name) == true && title.contains("training") == true) //this line would NOT work if "eventlist" was still a collection variable, so I had to convert it to List variable
- {
- sessioncount +=1;
- }
- }
- mp = Map();
- mp.put("Scheduled Sessions",sessioncount);
- info name;
- info sessioncount;
- info mp;
- //update = zoho.crm.updateRecord("Contacts",ident,mp);
- //info update;
- }
Obviously problems there. Now trying to use the CoQL api, but I've never done APIs before.
Relevant code below. You can see several versions of the searchRecords task based on different community/help docs, but none seem to work.
Code below just tries to return ALL the Meetings in the current month to get proof of concept. Returns Invalid Query. Sessioncount should be 116, but returns 4... I have no idea where that's from.