Create Record

Creating Records

You can create one or more records in Zoho CRM by using invokeConnector() Deluge task.

Syntax

<CRM Response> = zoho.crm.invokeConnector("crm.create", <Module & Field values map>);

where,
<CRM Response> is the map variable returned by CRM as response.
<Module & Field values> is the map variable that holds the key,value pairs. The two mandatory keys are "module" and "data".
A brief description of the keys are given below.

KeyDatatypeDescription
module*StringSpecify the module's API name where you want to create a record.
data*ListProvide the Record details in Map format to get inserted into the module as
{"Last_Name":"JoJo", "Company":"ABT"}.
These keys are Field API names and can be referred from the right side listing of the Custom function builder.
data = {"Last_Name":"JoJo", "Company":"ABT"};
l = list();
l.add(data);

Multiple records can be created simultaneously by adding multiple Maps into this list.
wfTriggerBooleanSet this parameter value to "true" to trigger the workflow rule while inserting the record.By default it is "false".

Example

For example, the steps to create a lead in CRM from an existing contact the below script can be written.

myFieldMap = map();
myFieldMap.put("Last_Name", input.contact.get("Last_Name"));
myFieldMap.put("Phone", input.contact.get("Phone"));
myFieldMap.put("Email", input.contact.get("Email"));
l = list();
l.add(myFieldMap);
dataMap = map();
dataMap.put("module", "Leads");
dataMap.put("data", l); //function to push data to CRM
response = zoho.crm.invokeConnector("crm.create", dataMap);
info response;

Function explanation:

  • Using crm.create in invoke connector task helps us to add new record in CRM.
  • CRM Module Name and the Fields map are passed to the function to make sure the right record is added to the right module.
  • response stores the result of the action (success or failure with the record ID of the CRM module).

 Note : This example captures only 4 basic fields from CRM Leads module. You can use other fields in the same method too.

 Response Format

{"status_code":200,"response":"{"data":[{"message":"record added","details":{"created_by":{"id":"1297376000000094003","name":"ZohoDemo"},"id":"1297376000000128001","modified_by":{"id":"1297376000000094003","name":"ZohoTest"},"modified_time":"2016-06-14T16:35:02+05:30","created_time":"2016-06-14T16:35:02+05:30"},"status":"success","code":"SUCCESS"}]}"}

 Getting ID of the CRM record

Sample code to get the ID of the CRM record created using the crm.create task is given below. 

myFieldMap = map();
myFieldMap.put("Last_Name", input.contact.get("Last_Name"));
myFieldMap.put("Phone", input.contact.get("Phone"));
myFieldMap.put("Email", input.contact.get("Email"));
l = list();
l.add(myFieldMap);
dataMap = map();
dataMap.put("module", "Leads");
dataMap.put("data", l);
crmResp = zoho.crm.invokeConnector("crm.create", dataMap);
resp =crmResp.get("response").toMap();
data = resp.get("data").toJSONList();
for each d in data
{
respMap = d.toMap();
dataDet = respMap.get("details").toMap();  
currentid = dataDet.get("id").toLong();
}

where,
crmResp is the map variable returned by CRM for the crm.create task and contains the ID value of the created crm record.
crmResp.get("Id") will return the ID value of the created crm record. Please refer the sample response format here .
To update the record based on the record id:

updateMap = map();
updateMap.put("module", "Contacts");
dataMap = {"id", currentid+"", "Last_Name" : "JoJo" };
dataList = list();
dataList.add(dataMap);
updateMap.put("data", dataList);
crmResp = zoho.crm.invokeConnector("crm.update", updateMap);

Note:
To fetch the ID value from CRM, for a given last name, you can first use task to get the id value from the returned map variable and then use the updateRecord  task.

 Creating a task with Contact and Account Lookup

taskInfo = map();
taskInfo.put("Task Owner", input.Owner_Name);
taskInfo.put("SMOWNERID", input.Owner_ID);
taskInfo.put("Subject", input.Subject);
taskInfo.put("Description", input.Description);
taskInfo.put("SEMODULE", "Accounts");
taskInfo.put("SEID", input.Account_ID);
taskInfo.put("CONTACTID", input.Contact_ID};
l = list();
l.add(taskInfo);
m1 = {"module": "Tasks", "data": l};
crmResp = zoho.crm.invokeConnector("crm.create", m1);

where,

SMOWNERID is the ID of the Owner
SEMODULE can be Accounts or Leads or Cases
SEID is the ID of the Record given in the SEMODULE
CONTACTID is the ID of the contact record

 Creating a lead in Zoho CRM and adding a note to the Lead

Sample script to create a "Lead" in Zoho CRM and then add a note to that Lead is given below:

leadinfo = { "Company" : "Test", "First Name" : "Test", "Last Name" : "Rec", "Email" : "test@zoho.com ", "Phone" : "1234567", "Address" :  "Test", "City" : "Test", "State/Province" : "Test", "Country" : "Test"};
leadList = list();
leadList.add(leadinfo);
leadMap = {"module": "Leads", "data": leadList};
crmResp = zoho.crm.invokeConnector("crm.create", leadMap);
resp = crmResp.get("response").toMap();
leadRecords = resp.get("data").toJSONList();
for each leadRecord in leadRecords
{
      leadMap = leadRecord.toMap();
      leadDet = leadMap.get("details").toMap();
      entityId = leadDet.get("id");
      notesMap = { "entityId" : entityId, "Note Title" : "Zoho CRM Sample Note", "Note Content" : "This is sample content to test." };
      l = list();
      l.add(notesMap);
      newMap = {"module": "Notes", "data": l};
      notesResp = zoho.crm.invokeConnector("crm.create", newMap);
}

 Related Topics

https://www.zoho.com/crm/help/api/insertrecords.html 

Share this post :

FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohodeveloper.com