try { newAccessTokenResp = invokeurl [ url :"https://accounts.zoho.com/oauth/v2/token?refresh_token=1000.4dbfd6f3f7f126438dfb3401fd8dd576.4a3dede786ffa5cb2eb17686172b500e&client_id=1000.SYSU4K6QTILBGIZXBYI9MP7B1SBXYD&client_secret=9397985b78e1b9d2ddd6d3bd39f2da147fbe278489&redirect_uri=https://accounts.zohoportal.com/accounts/extoauth/clientcallback&grant_type=refresh_token" type :POST ]; newAccessToken = newAccessTokenResp.get("access_token"); O_AuthToken = Map(); O_AuthToken.put("Authorization","Zoho-oauthtoken " + newAccessToken + ""); //info O_AuthToken; /////Get latest Employee ID FROM Zoho People/////// People_Rec_ID = 448415000045594312; get_Data = zoho.people.getRecordByID("Latest_Employee_ID_Employee_Users",People_Rec_ID); //info get_Data; get_latatest_emp_id = get_Data.get("Latest_Employee_ID"); info "latest employee id: " + get_latatest_emp_id; ////////// /////////// ////// get_data = invokeurl [ url :"https://recruit.zoho.com/recruit/v2/Candidates/" + rec_id + "" type :GET headers:O_AuthToken ]; //info get_data; data = get_data.get("data"); for each data in data { //info data; Candidate_Status = data.get("Candidate_Status"); //info Candidate_Status; if(Candidate_Status == "Hired") { First_name = data.get("FirstName"); //info First_name; Last_Name = data.get("LastName"); //info Last_Name; //////////// //////// department = data.get("Employee_Department").get("id"); //info department; ///// ////////// get_department_data = invokeurl [ url :"https://recruit.zoho.com/recruit/v2/Departments/" + department + "" type :GET headers:O_AuthToken ]; //info get_department_data; dep_data = get_department_data.get("data"); //info "Department Data RECRUIT" + dep_data; for each rec in dep_data { zoho_people_dep_id = rec.get("Zoho_People_Rec_ID"); //info zoho_people_dep_id; } /////// ////// //info Employee_id; Street = data.get("Street"); City = data.get("City"); State = data.get("State"); Country = data.get("Country"); Mobile = data.get("Mobile"); address = Street + " " + City + " " + State + " " + Country; //info address; //Secondary_Email = data.get("Secondary_Email"); Department = data.get("Employee_Department").get("name"); ////prob //info Department; Employee_Seating_Location = data.get("Employee_Seating_Location"); //info Employee_Seating_Location; Title_Designation = data.get("Employee_Designation_Title"); //info Title_Designation; Client_Type = ifnull(data.get("Client_Type"),""); if(Client_Type == "External") { Client_Name = ifnull(data.get("Client_Name"),""); //Billing_Rate = ifnull(data.get("Billing_Rate").toDecimal(),0.00); } else { Client_Name = ""; Billing_Rate = 0.00; } Manager_s_Email_ID = data.get("Manager_s_Email_ID"); info Manager_s_Email_ID; Zoho_Access_Required = data.get("Zoho_Access_Required"); //info Title_Designation; Date_Of_joining = data.get("Date_Of_joining").toString("dd-MMM-yyyy"); //info Date_Of_joining; Location = data.get("Employee_Seating_Location"); ///prob //info Location; Working_hrs = data.get("Shift_Timings"); //info Working_hrs; Employee_Role = ifnull(data.get("Employee_Role"),""); //info Employee_Role; Email_Client = ifnull(data.get("Email_Client"),""); //info Email_Client; Employee_type = data.get("Employee_type"); //Email_id = data.get("Email"); // // ////////// //find find location, desigination, department //https://people.zoho.com/people/api/forms/department/views AllDesignations = list(); fetchDesignationsList = {1,2,3,4,5,6,7,8,9,10}; for each designationList in fetchDesignationsList { if(designationList == 1) { startIndex = 1; } else { startIndex = (designationList - 1) * 100 + 1; } get_designation = invokeurl [ url :"https://people.zoho.com/people/api/forms/P_DesignationView/records?sIndex=" + startIndex + "&rec_limit=100" type :GET headers:O_AuthToken ]; //info get_designation; for each des in get_designation { AllDesignations.add(des); } if(get_designation.size() < 100) { break; } } designationID = null; for each desig in AllDesignations { if(desig.get("Designation Name") == Title_Designation) { designationID = desig.get("recordId"); //info designationID; break; } } //info designationID; // // //////////////////////// //// /////for adding reporting to /////////////////// get_manager_data = invokeurl [ url :"https://people.zoho.com/people/api/forms/employee/getRecords?searchParams={searchField: 'EmailID', searchOperator: 'Is', searchText : " + Manager_s_Email_ID + "}" type :GET headers:O_AuthToken ]; data = get_manager_data.get("response").get("result"); //info "manager data" + data; for each data in data { manager_id = data.keys(); //info "Manager email id: " + manager_id; manager_id = manager_id.substring(0); manager_id = manager_id.toNumber(); } ///////////////// ///////////// ///////////////// /////////////////// data = {"EmployeeID":get_latatest_emp_id,"FirstName":First_name,"LastName":Last_Name,"Work_location":Location,"Designation":designationID,"Dateofjoining":Date_Of_joining,"Working_Hours":Working_hrs,"Role":Employee_Role,"Email_Client":Email_Client,"Employee_type":Employee_type,"Department":zoho_people_dep_id,"Zoho_Access_Required":Zoho_Access_Required,"Reporting_To":manager_id,"Client_Type":Client_Type,"Client_Name":Client_Name}; inputdata = Collection(); inputdata.insert("inputData":data); inputdata.insert("isNonUser":true); create_employee = invokeurl [ url :"https://people.zoho.com/people/api/forms/json/employee/insertRecord" type :POST parameters:inputdata.toMap() headers:O_AuthToken ]; info "Create employee response: " + create_employee; } } } catch (e) { sendmail [ from :zoho.adminuserid to :"usman@erphub.biz","auto@rebiz.zohodesk.com" subject :"Zoho Recruit/Workflow Failure/create_employee_on_zoho_people / " + First_name + Last_Name message :e + " RECORD ID: " + rec_id ] }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter