This is a quick article to note down some code used in Zoho Recruit. This particular bit of code will run on a workflow when a Candidate is modified, and it tallies all the candidates belonging to the same school and updates some number fields on the matched CRM account.
Why?
For reporting purposes. Although Zoho Analytics can use data imported from both ZohoCRM and ZohoRecruit, it was helpful on the CRM record to see how many candidates had been placed at this particular CRM Account. We added several fields which get populated when a candidate was modified in ZohoRecruit.
How?
As mentioned, we're going to update several fields called:
- Number of Candidates This Graduation Year
- Number of Candidates Next Graduation Year
- Candidates Graduated in the Past
- Candidates Graduating in the Future
- Total Number of Candidates
r_CandidateDetails = zoho.recruit.getRecordById("Candidates",p_CandidateID,"zrecruit"); //info r_CandidateDetails; if(!isNull(r_CandidateDetails.get("Which School do you go to?"))) { v_SchoolName = r_CandidateDetails.get("Which School do you go to?"); v_SchoolID = r_CandidateDetails.get("Which School do you go to?_ID"); b_SchoolPaid = if(r_CandidateDetails.get("Paid School") == "true",true,false); // v_CandidatePlacedCount = 0; v_CandidateGraduatingCount = 0; v_CandidateGraduatingNextCount = 0; l_CandidateSearch = zoho.recruit.searchRecords("Candidates","School Name|=|" + v_SchoolName,1,200,"ALL","zrecruit"); for each r_Candidate in l_CandidateSearch { if(!isnull(r_Candidate.get("CANDIDATEID"))) { v_CandidatePlacedCount = v_CandidatePlacedCount + 1; r_CandidateDetail = zoho.recruit.getRecordById("Candidates",r_Candidate.get("CANDIDATEID"),"zrecruit"); if(!isnull(r_CandidateDetail.get("Graduation Year"))) { v_GraduationYear = r_CandidateDetail.get("Graduation Year"); if(v_GraduationYear == zoho.currentdate.addYear(1).getYear() && zoho.currentdate.getMonth() >= 9 || v_GraduationYear == zoho.currentdate.getYear() && zoho.currentdate.getMonth() < 9) { v_CandidateGraduatingCount = v_CandidateGraduatingCount + 1; } if(v_GraduationYear == zoho.currentdate.addYear(2).getYear() && zoho.currentdate.getMonth() >= 9 || v_GraduationYear == zoho.currentdate.addYear(1).getYear() && zoho.currentdate.getMonth() < 9) { v_CandidateGraduatingNextCount = v_CandidateGraduatingNextCount + 1; } } } } // m_Blank = Map(); l_SchoolSearch = zoho.crm.searchRecords("Accounts","Account_Name:equals:" + v_SchoolName,1,10,m_Blank,"zcrm"); for each r_School in l_SchoolSearch { // check no search error and valid records are returned if(!isnull(r_School.get("id"))) { // check this record is the same school if(r_School.get("Account_Name").equalsIgnoreCase(v_SchoolName)) { // update the CRM record m_Trigger = Map(); m_Update = Map(); m_Update.put("Total_Number_of_Candidates",v_CandidatePlacedCount); m_Update.put("Number_of_Candidates_This_Graduation_Year",v_CandidateGraduatingCount); m_Update.put("Number_of_Candidates_Next_Graduation_Year",v_CandidateGraduatingNextCount); r_Update = zoho.crm.updateRecord("Accounts",r_School.get("id"),m_Update,m_Trigger,"zcrm"); info r_Update; } } } }
- r_CandidateDetails = zoho.recruit.getRecordById("Candidates",p_CandidateID,"zrecruit");
- //info r_CandidateDetails;
- if(!isNull(r_CandidateDetails.get("Which School do you go to?")))
- {
- v_SchoolName = r_CandidateDetails.get("Which School do you go to?");
- v_SchoolID = r_CandidateDetails.get("Which School do you go to?_ID");
- b_SchoolPaid = if(r_CandidateDetails.get("Paid School") == "true",true,false);
- //
- v_CandidatePlacedCount = 0;
- v_CandidateGraduatingCount = 0;
- v_CandidateGraduatingNextCount = 0;
- l_CandidateSearch = zoho.recruit.searchRecords("Candidates","School Name|=|" + v_SchoolName,1,200,"ALL","zrecruit");
- for each r_Candidate in l_CandidateSearch
- {
- if(!isnull(r_Candidate.get("CANDIDATEID")))
- {
- v_CandidatePlacedCount = v_CandidatePlacedCount + 1;
- r_CandidateDetail = zoho.recruit.getRecordById("Candidates",r_Candidate.get("CANDIDATEID"),"zrecruit");
- if(!isnull(r_CandidateDetail.get("Graduation Year")))
- {
- v_GraduationYear = r_CandidateDetail.get("Graduation Year");
- if(v_GraduationYear == zoho.currentdate.addYear(1).getYear() && zoho.currentdate.getMonth() >= 9 || v_GraduationYear == zoho.currentdate.getYear() && zoho.currentdate.getMonth() < 9)
- {
- v_CandidateGraduatingCount = v_CandidateGraduatingCount + 1;
- }
- if(v_GraduationYear == zoho.currentdate.addYear(2).getYear() && zoho.currentdate.getMonth() >= 9 || v_GraduationYear == zoho.currentdate.addYear(1).getYear() && zoho.currentdate.getMonth() < 9)
- {
- v_CandidateGraduatingNextCount = v_CandidateGraduatingNextCount + 1;
- }
- }
- }
- }
- //
- m_Blank = Map();
- l_SchoolSearch = zoho.crm.searchRecords("Accounts","Account_Name:equals:" + v_SchoolName,1,10,m_Blank,"zcrm");
- for each r_School in l_SchoolSearch
- {
- // check no search error and valid records are returned
- if(!isnull(r_School.get("id")))
- {
- // check this record is the same school
- if(r_School.get("Account_Name").equalsIgnoreCase(v_SchoolName))
- {
- // update the CRM record
- m_Trigger = Map();
- m_Update = Map();
- m_Update.put("Total_Number_of_Candidates",v_CandidatePlacedCount);
- m_Update.put("Number_of_Candidates_This_Graduation_Year",v_CandidateGraduatingCount);
- m_Update.put("Number_of_Candidates_Next_Graduation_Year",v_CandidateGraduatingNextCount);
- r_Update = zoho.crm.updateRecord("Accounts",r_School.get("id"),m_Update,m_Trigger,"zcrm");
- info r_Update;
- }
- }
- }
- }