This guide will help you with the following:
- Syntax
- Example
- Response Format
- Additional Examples
- Fetching ID of a record created using the zoho.crm.createRecord() task
- Creating a task with chosen Contact and Account lookups
- Creating a Lead record and adding a Note to it
You can create records in Extensions and Vertical Solutions using the zoho.crm.createRecord() deluge task.
Syntax
- <Response> = zoho.crm.createRecord(<module String>,<dataMap Map>,<optionalDataMap Map>);
where,
<Response> is the task response returned as a Map.
Parameters
Example
Create a Lead record and trigger associated workflows
Obtain as user input, the last name, phone number, and email address of the Lead and create a record with these details. The sample script is given below:
- newRecordInfo = Map();
- newRecordInfo.put("Last_Name",lead.get("Last_Name"));
- newRecordInfo.put("Phone",lead.get("Phone"));
- newRecordInfo.put("Email",lead.get("Email"));
- response = zoho.crm.createRecord("Leads",newRecordInfo,{"trigger":{"workflow"}});
- info response;
Explanation:
- The Lead details obtained as user inputs are populated in a map (newRecordInfo).
- {"trigger":{"workflow"}} ensures that all workflows associated with creation of a Lead is triggered.
- response stores the result of the action (success or failure with the ID of the newly created record).
- {"Modified_Time":"2018-10-25T10:38:28+05:30",
- "Modified_By":
- {"name":"ZohoDemo","id":"3388926000000166021"},
- "Created_Time":"2018-10-25T10:38:28+05:30",
- "id":"3388926000000313001",
- "Created_By":{"name":"ZohoTest","id":"3388926000000166021"}
- }
Additional Examples
Fetching ID of a record created using the zoho.crm.createRecord() task
The sample script is given below:
- newRecordInfo = Map();
- newRecordInfo.put("Last_Name",lead.get("Last_Name"));
- newRecordInfo.put("Phone",lead.get("Phone"));
- newRecordInfo.put("Email",lead.get("Email"));
- response = zoho.crm.createRecord("Leads",newRecordInfo);
- info "response: " + response;
- id = response.get("id");
- info "id: " + id;
Response
- response: {"Modified_Time":"2018-10-25T10:45:26+05:30","Modified_By":{"name":"ZohoDemo","id":"3388926000000166021"},"Created_Time":"2018-10-25T10:45:26+05:30","id":"3388926000000314001","Created_By":{"name":"ZohoTest","id":"3388926000000166021"}}
- id: 3388926000000314001
Update a record using the record ID
The record in Leads module with ID 3388926000000314001 will be updated with the last name 'John'. The sample script is given below:
- updateMap = Map();
- updateMap.put("Last_Name","John");
- response = zoho.crm.updateRecord("Leads",3388926000000314001,updateMap);
- info response;
Response
- {"Modified_Time":"2018-10-25T10:50:15+05:30","Modified_By":{"name":"ZohoDemo","id":"3388926000000166021"},"Created_Time":"2018-10-25T10:38:28+05:30","id":"3388926000000313001","Created_By":{"name":"ZohoTest","id":"3388926000000166021"}}
Creating a task with chosen Contact and Account lookups
The sample script is given below:
- taskInfo = Map();
- taskInfo.put("Subject",task.get("Subject"));
- taskInfo.put("Description",task.get("Description"));
- taskInfo.put("$se_module","Accounts");
- contactInfo = {"name":"Arthur","id":"3388926000000285001"};
- taskInfo.put("Who_Id",contactInfo);
- accInfo = {"name":"Acme Inc","id":"3388926000000297008"};
- taskInfo.put("What_Id",accInfo);
- response = zoho.crm.createRecord("Tasks",taskInfo);
- info response;
where,
- $se_module can be Accounts, Leads, or Cases
- contactInfo is the map having Contact lookup details
- accInfo is the map having Account lookup details
Response
- {"Modified_Time":"2018-10-25T10:54:13+05:30",
- "Modified_By":{"name":"ZohoTest","id":"3388926000000166021"},
- "Created_Time":"2018-10-25T10:54:13+05:30",
- "id":"3388926000000314014",
- "Created_By":{"name":"ZohoTest","id":"3388926000000166021"}
- }
Creating a Lead record and adding a Note to it
The sample script is given below:
- leadInfo = {"Company":"Zoho","First_Name":"Mary","Last_Name":"John","Email":"mary.j@zylker.com","Phone":"14081234567","Street":"Elm Street","City":"Vegas","State":"Texas","Country":"USA"};
- resp = zoho.crm.createRecord("Leads",leadInfo);
- leadId = resp.get("id");
- noteInfo = {"Parent_Id":leadId,"Note Title":"Note for Contact","Note_Content":"This is a sample note","$se_module":"Leads"};
- response = zoho.crm.createRecord("Notes",noteInfo);
- info response;
Response
- {"Modified_Time":"2018-10-25T10:57:19+05:30","Modified_By":{"name":"ZohoTest","id":"3388926000000166021"},"Created_Time":"2018-10-25T10:57:19+05:30","id":"3388926000000316007","Created_By":{"name":"ZohoTest","id":"3388926000000166021"}}