try { info time_sheet; Assignees = ""; Sr_idlist = list(); sr_emailid_list = list(); time = toNumber(60); Start_Date = time_sheet.get("Start_Date_Time").getPrefix("T"); End_Date = time_sheet.get("End_Date_Time"); if(!End_Date.isNull() && !End_Date.isEmpty()) { End_Date = End_Date.getPrefix("T"); } Job_name = time_sheet.get("Service_Appointment").get("name"); duration = time_sheet.get("Duration"); if(!duration.isNull() && !duration.isEmpty()) { duration = duration.toNumber(); var = duration / time; info var; var=var.round(2); time_sheetname = time_sheet.get("Name"); Sr_id = time_sheet.get("Service_Resource").toMap().get("id"); info Sr_id; response = invokeurl [ url :"https://fsm.zoho.com/fsm/v1/users" type :GET connection:"fsmconnection" ]; // info Sr_idlist; usr_li = response.get("users").toList(); for each sample in usr_li { usr_sr_id = sample.get("Service_Resources").get("id"); info usr_sr_id; if(Sr_id == usr_sr_id) { sr_emailid = sample.get("email"); break; } } //info time_sheet; Service_appointment_id = time_sheet.get("Service_Appointment").get("id"); ser_app_resp = zoho.fsm.getRecordById("Service_Appointments",Service_appointment_id); // info ser_app_resp; job_id = ser_app_resp.get("data").toMap().get("zoho_People_job_Id__C"); if(job_id == null || job_id == "") { Service_Appointment_X_Service_Resources = ser_app_resp.get("data").toMap().get("$Service_Resources"); // info Service_Appointment_X_Service_Resources; for each Service_Resources in Service_Appointment_X_Service_Resources { Service_Resource_id = Service_Resources.toMap().get("id"); Sr_idlist.add(Service_Resource_id); } for each sample in usr_li { usr_sr_id = sample.get("Service_Resources").get("id"); if(Sr_idlist.contains(usr_sr_id)) { sr_emailid_list.add(sample.get("email")); } } // info sr_emailid_list; for each email in sr_emailid_list { searchMap = Map(); searchMap.put("searchField","EmailID"); searchMap.put("searchOperator","Is"); searchMap.put("searchText",email); response = zoho.people.getRecords("P_Employee",0,50,searchMap).toMap(); // info response; if(response.contains("EmployeeID")) { Zoho_ID = response.get("Zoho_ID"); // info Zoho_ID; if(Assignees != null && Assignees != "") { Assignees = Assignees + ";" + Zoho_ID; } else { Assignees = Zoho_ID; } } } // info Assignees; if(Assignees != null && Assignees != "") { inputData = {"Job_Name":Job_name,"Assignees":Assignees}; info inputData; response = zoho.people.create("P_TimesheetJob",inputData); info response; job_id = response.toMap().get("result").get("pkId"); info zoho.fsm.updateRecord("Service_Appointments",Service_appointment_id,{"zoho_People_job_Id__C":job_id}); } } info sr_emailid; event = Map(); event.put("user",sr_emailid); event.put("workDate",Start_Date); event.put("jobId",job_id); event.put("hours",var); event.put("billingStatus","Billable"); info event; response = invokeurl [ url :"https://people.zoho.com/people/api/timetracker/addtimelog" type :post parameters:event connection:"zohopeoplecon" ]; info response; data = Map(); data.put("user",sr_emailid); data.put("timesheetName",time_sheetname); data.put("fromDate",Start_Date); data.put("toDate",End_Date); data.put("jobId",job_id); info data; response = invokeurl [ url :"https://people.zoho.com/people/api/timetracker/createtimesheet" type :post parameters:data connection:"zohopeoplecon" ]; info response; } } catch (error) { info error; // sendmail // [ // from :zoho.adminuserid // to :zoho.adminuserid // subject :"Timesheet creation failed" // message :error // ] } |
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.