Create a record in Zoho CRM

Table of Contentsup

Overview

The create() Deluge task is used to create a new record in any of the modules in your CRM account (Leads, Accounts, Contacts, Potentials), directly from your Zoho Creator appliction. For example, add contact info submitted via a creator form as a Lead in Zoho CRM.

Syntax

<CRM Response> = zoho.crm.create(<CRM Module Name>, <Field values as map value>, <optional duplicateCheck as Integer>);

where,
<CRM Response> is the map variable returned by CRM as response.
<CRM Module Name>is the name of the CRM module where the record will be added. For example, "Leads" refers to the Leads module. Click here to view the list of supported modules.
<Field values> is the map variable that holds the key,value pairs. The map key is the label name as specified in the CRM module and the map value is the field value in Zoho Creator. For example, "Company" : input.Company_Name . Here, "Company" is the label name as specified in the crm module and input.Company_Name refers to the value specified in the Company_Name field in Zoho Creator. Click here to view the list of supported fields of different modules.
<duplicateCheck> Set value as "1" to check the duplicate records and throw an error response or "2" check the duplicate records, if exists, update the same. If the value is not specified, duplicate check will not be performed. Refer here for more details about duplicate check.

Response Format

Success Response

The response returned will be in the format given below:

{
"message":"Record(s) added successfully","Created Time":"2011-06-14 12:28:11","Modified By":"ZohoTest","Id":"1584000000028003",
"Modified Time":"2011-06-14 12:28:11", "Created By":"ZohoTest"
}

Error Response

If the execution fails due to incorrect parameter value,the response will be in the following format:

4832You have given a wrong value for the field : Contact Name

You can refer this link for the list of error codes.

Supported Modules

  • Leads
  • Contacts
  • Events
  • Tasks
  • Potentials
  • Accounts
  • Cases
  • Solutions
  • Products
  • Pricebooks
  • Vendors
  • Quotes
  • Purchaseorders
  • Salesorders
  • Invoices
  • Campaigns

The supported fields in each module can be referred from CRM Modules and fields.

Examples

a. Create a new Lead in CRM

A sample script to create a new lead in Zoho CRM Leads module is given below. You can execute this script from a Zoho Creator form by adding it to the required Form Actions block. For example, to create a lead in the Leads module, based on the values submitted from a Zoho Creator form,

a. Select Form Settings > On Add > Actions On Success section of the above Form. This will display the script builder in free-flow scripting mode, with the On Success block selected.

b. Write the script as given below and click on Save Script.

//create the CRM vs Creator fields map to push data to the CRM module.

myFieldMap = map();

//add values to the map. CRM fields first and then Creator fields ( without the quotes ). Creator field’s deluge name is used here.

myFieldMap = map();

myFieldMap.put(“Company”, input.Company_Name);
myFieldMap.put(“Last Name”, input.Name);
myFieldMap.put(“Phone”, input.Telephone);
myFieldMap.put(“Email”, input.Email_Address);
//function to push data to CRM
crmResponse = zoho.crm.create(“Leads”, myFieldMap);

Function explanation:

  • zoho.crm.create() is the function that tells Zoho Creator system to add new record in CRM.
  • crmResponse 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.

b. Get ID of the new Lead

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

//function to push data to CRM
crmResponse = zoho.crm.create(“Leads”, myFieldMap);
currentid = (crmResponse.get("Id")).toLong();

where,

crmResponse is the map variable returned by CRM for the zoho.crm.create() task and contains the ID value of the created crm record.

crmResponse.get("Id") will return the ID value of the created crm record. Please refer the sample response format here.

c. Upload Files to CRM

A file uploaded in Zoho Creator using the File upload field, can be pushed to Zoho CRM as an attachment in the zoho.crm.create() task. The key name for referring to attachment is Attachment in both syntax and response.

Example

myFieldMap = map();
myFieldMap.put("Company", input.Company_Name);
myFieldMap.put("Last Name", input.Name);
myFieldMap.put("Phone", input.Telephone);
myFieldMap.put("Email", input.Email_Address);
myFieldMap.put("Attachment", input.File_upload);
myFieldMap.put("Lead Source", input.Lead_Source);
response = zoho.crm.create("Leads", myFieldMap);

where,

Attachment is the key name which refers to the file attachment.
input.File_upload refers to the File_upload field value.

Response

{"message":"Record(s)added successfully","Attachment":"File has been attached successfully" ,"Created Time":"2012-06-08 05:45:50","Modified
By":"Test","Id":"231356000000189001","Modified Time":"2012-06-08 05:45:50","Created By":"Test"};

e. Add a note to a Lead

Sample script to add a note to a Lead with a given ID.

//Adding notes to a Lead
notesMap = { "entityId" : "262950000000274001", "Note Title" : "Zoho CRM Sample Note", "Note Content" : "This is sample content to test." };
notesResponse = zoho.crm.create("Notes", notesMap);

d. Create a task with Contact and Account Lookup

taskInfo = {
"Task Owner" : input.Owner_Name,
"SMOWNERID" : input.Owner_ID,
"Subject" : input.Subject,
"Description" : input.Description,
"SEMODULE" : "Accounts",
"SEID" : input.Account_ID,
"CONTACTID" : input.Contact_ID};
crmResponse = zoho.crm.create("Tasks", taskInfo);

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

f. Create a new Invoice in CRM

A sample script to create a new record in Zoho CRM Invoices module is given below. You can execute this script from a Zoho Creator form by adding it to the required Form Actions block. For example, to add a record to the Invoices module, based on the values submitted from a Zoho Creator form,

a. Select Form Settings > On Add > Actions On Success section of the above Form. This will display the script builder in free-flow scripting mode, with the On Success block selected.

b. Write the script as given below and click on Save Script.

product_id = 195737000000116003;
InvoiceMap = map();
InvoiceMap.put("Subject", "Your Order Number.001");
InvoiceMap.put(("Account Name"), "Max");
InvoiceMap.put("Billing Street", "10, Downing Street");
InvoiceMap.put("Billing City", "Chennai");
InvoiceMap.put("Billing State", "TamilNadu");
InvoiceMap.put("Billing Country", "India");
Products_Map = map();
Products_Map.put("Product Id", product_id);
Products_Map.put("Quantity", 2);
Products_Map.put("Unit Price", 100);
Products_Map.put("Product Id", product_id);
Products_Map.put("Quantity", 2);
Products_Map.put("Unit Price", 50000);
Products_List = List();
Products_List.add(Products_Map);
InvoiceMap.put("Products", Products_List);
InvoiceMapResponse = zoho.crm.create("Invoices", InvoiceMap);
info InvoiceMapResponse;

Function explanation:

  • product_id is the variable which holds the id of the product as specified in CRM "Products" module
  • InvoiceMap is the map variable which holds the field, value mapping for the invoice.
  • Products_Map is the map variable which holds the product details
  • Products_List is the list variable which holds the list of all products
  • zoho.crm.create() is the function that tells Zoho Creator system to add new record in CRM.
  • crmResponse stores the result of the action (success or failure with the record ID of the CRM module).

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

g. Create a new event in Zoho CRM

A sample script to create a new event in Zoho CRM is given below. You can execute this script from a Zoho Creator form by adding it to the required Form Actions block. For example, to create a new event in Zoho CRM, based on the values submitted from a Zoho Creator form,

a. Select Form Settings > On Add > Actions On Success section of the above Form. This will display the script builder in free-flow scripting mode, with the On Success block selected.

b. Write the script as given below and click on Save Script.

//create the CRM vs Creator fields map to push data to the CRM module.

myFieldMap = map();

//add values to the map. CRM fields first and then Creator fields ( without the quotes ). Creator field’s deluge name is used here.

myFieldMap = map();

myFieldMap.put(“Subject”, Subject);
myFieldMap.put(“Start Date Time”, Start_Date_Time);
myFieldMap.put(“End Date Time”, End_Date_Time);
//function to push data to CRM
crmResponse = zoho.crm.create(“Events”, myFieldMap);

Function explanation:

  • zoho.crm.create() is the function that tells Zoho Creator system to add new record in CRM.
  • CRM Module Name and the Fields map (refer section 2.1) are passed to the function to make sure the right record is added to the right module.
  • crmResponse stores the result of the action (success or failure with the record ID of the CRM module).

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

Using Script Builder

You can also add the script using the drag-n-drop functionality in Script Builder. The following example demonstrates the usage of script builder to insert the "Create" function.

  1. Select the Form from your Dashboard page
  2. Click on Settings - On Add - Actions on Success
  3. Click on Script Builder from the top-right corner of the page.
  4. Drag and drop the call function in the editor box.
  5. Select Integration tasks.
  6. Select the Service as Zoho CRM and the function as create.
  7. Select the required CRM Module to which the record will be added.
  8. The Field values as map will list the map variable that holds the key value pairs, if already defined. Click on New Map link to specify the key, value pairs.
  9. Specify the CRM Response Variable and click Done to add the task to the script builder.
  10. Click Save Script to add the script. The script will be executed when a record is added to the "Create" form. It will add a record to the "Leads" module in Zoho CRM.

Sample Application

https://creator.zoho.com/sampleapps/push-data-to-zoho-crm#

Related Topics

https://forums.zoho.com/topic/map-tutorial-%28beginners%29

/crm/help/api/insertrecords.html

Share this post : FacebookTwitter