Create Project while winning potentials - Projects v3 api updated code
Hi all, I've been using the built in function to create a project while a deal is closed won and noticed it had some missing fields when trying to reference the zoho projects v3 api documentation. Specifically the project group had some issues when adding which caused me to have to change the project creation code from zoho.projects.createproject to an api call.
I wanted to share my code in case some other people had some issues similar because this took some time to figure out and a few messages to support. A couple important notes, with the built in function I used custom field column names to populate them, with the v3 call I can reference their api names. If youre having troubles finding the custom project fields api names I used these calls in crm as standalone functions to reference them:
- response = invokeurl
- [
- url :"https://projectsapi.zoho.com/api/v3/portal/[portal id]/module/[project module id]/fields"
- type :GET
- connection:"zohoprojects"
- ];
- info response;
Also to get your projects module information I did the same thing with this url:
- url :"https://projectsapi.zoho.com/api/v3/portal/[portal id]/settings/modules"
Finally I will share my code for reference and some comments to show my changes,
- void automation.Create_Projects_for_Closed_Potentials2(String ProjName,String PortalName,String TemplateID,String Description,Date startdate,Date enddate,String id)
- {
- /*
- ProjName = Jobs.Jobs Name
- Description = Jobs.Description
- startdate = Jobs.Last Activity Time
- enddate = Jobs.Closing Date (This can be changed will see)
- id = Jobs.Jobs Id
- PortalName = name of our portal - Depreciated parameter
- TemplateID = ######### (Template id found in template url)
- */
- createMap = Map();
- dealRecord = zoho.crm.getRecordById("Deals",id.toLong());
- descriptionText = " Job Schedule:";
- jobDays = dealRecord.get("Job_Days");
- if(jobDays != null)
- {
- descriptionText = "";
- moveDateRaw = null;
- for each row in jobDays
- {
- d = ifnull(row.get("Day"),"");
- tt = ifnull(row.get("Addresses_Needed"),"");
- des = ifnull(row.get("Description"),"");
- if(moveDateRaw == null && row.get("Date_Time") != null)
- {
- moveDateRaw = row.get("Date_Time").toDateTime().toDate();
- }
- line = "Address: " + tt + "Description: " + des;
- descriptionText = descriptionText + line;
- }
- if(moveDateRaw != null)
- {
- createMap.put("move_date_1",moveDateRaw.toString("yyyy-MM-dd")); // Custom field api, plus strict date formatting into projects
- }
- else
- {
- info "No valid Start_Time found in Job_Days.";
- }
- }
- else
- {
- info " jobDays is null. No subform data available.";
- }
- ProjName = dealRecord.get("Deal_Name");
- createMap.put("name",ProjName);
- createMap.put("description",Description);
- createMap.put("copy_from", TemplateID); // used to be the field "template_id"
- createMap.put("day",id); // custom field api name
- projectGroupMap = Map();
- projectGroupMap.put("id",######); // group id to assign project to on creation
- createMap.put("project_group",projectGroupMap);
- // Old create call, below is the new v3 api call
- // response = zoho.projects.createProject(PortalName,createMap,"zohooauth");
- resp = invokeurl
- [
- url :"https://projectsapi.zoho.com/api/v3/portal/[portal id]/projects"
- type :POST
- parameters:createMap.toString()
- connection:"zohoprojects"
- ];
- info "Project update response: " + resp.toString();
- projid = resp.get("id");
- if(projid != null)
- {
- updateMap = Map();
- updateMap.put("Project_ID",projid);
- updateResp = zoho.crm.updateRecord("Deals",id.toLong(),updateMap);
- info "Project ID stored in CRM: " + updateResp.toString();
- }
- assocMap = Map();
- assocMap.put("name",ProjName);
- assocList = List();
- assocList.add(assocMap);
- wrapper = Map();
- wrapper.put("data",assocList);
- response = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/Deals/" + id + "/Zoho_Projects/" + projid
- type :POST
- parameters:wrapper.toString()
- connection:"zohooauth"
- ];
- info "CRM Respopnse: " + response.toString();
- }