Hello everyone! Welcome to another week of Kaizen!
In last week's
post, we discussed in detail the configuration and initialization steps for PHP SDK. We will take you through sample codes for Record Operations this week, to help you get started with your SDK journey.
1. Custom Fields, Lookup Fields, Picklist Fields
1.1 Custom Fields
To set/update a value for a custom field during a record create/update, use addKeyValue method. This method takes two arguments - the field API name and the value.
$variable->addKeyValue("your_custom_field_api_name", "custom_field_value");
|
- $record->addKeyValue("Designation", "Manager");
1.2 Picklist Fields
To set/update a value for a default picklist field like 'Lead Source' in Leads module, use addFieldValue method in the following format.
$variable->addFieldValue(ModuleAPIName::FieldName(), new Choice("picklist_value")); |
- $record->addFieldValue(Contacts::LeadSource(), new Choice("Advertisement"));
Specify your option for the picklist field when you create the Choice class instance. In this example, the LeadsSoure picklist field in Contacts will be updated with the value Advertisement if it is a option for the picklist. If an invalid value is specified, the SDK will throw an UNACCEPTED VALUES ERROR.
For user defined Picklist fields, use the addKeyValue method in the following format.
$variable->addKeyValue("custom_picklist_field_api_name", new Choice("picklist_choice")); |
- $record->addKeyValue("Pick_List_2", new Choice("Option 1"));
1.3 Lookup Fields
To set/update a value for a default Lookup field during a record create/update, use addFieldValue method in the following format.
$lookupVariable = new Record(); $lookupVariable->addKeyValue("id", "lookup_record_id"); $recordVariable->addFieldValue(LookupModule::FieldName(), $lookupVariable); |
- $lookup = new Record();
- $lookup->addKeyValue("id", "554597402674230");
- $record->addFieldValue(Contacts::AccountName(), $lookup);
For custom Lookup fields, use the addKeyValue method in the following format.
$lookupVariable = new Record(); $lookupVariable->addKeyValue("id", "lookup_record_id"); $recordVariable->addKeyValue("Lookup_Field_API_Name", $lookupVariable); |
- $lookup = new Record();
- $lookup->addKeyValue("id", "55459742674230");
- $record->addKeyValue("Lookup_1", $lookup);
For Owner Lookup fields, use the addFieldValue method in the following format.
$ownerVariable = new User(); $recordVariable->addKeyValue("Owner_Field_API_Name", $recordVariable); |
- $recordOwner = new User();
- $recordOwner->setEmail("patricia.boyle@zylker.com");
- $record->addKeyValue("Owner", $recordOwner);
Sample Code for creating a new record in Contacts module with the above field types.
<?php use com\zoho\crm\api\HeaderMap; use com\zoho\crm\api\record\BodyWrapper; use com\zoho\crm\api\record\RecordOperations; use com\zoho\crm\api\record\Contacts; use com\zoho\crm\api\util\Choice; use com\zoho\crm\api\users\User; use com\zoho\crm\api\record\Record; require_once "vendor/autoload.php";
class CreateRecords { public static function initialize() { // add initialisation code // refer to the previous post for details and examples } public static function createRecords1(string $moduleAPIName) { $recordOperations = new RecordOperations(); $bodyWrapper = new BodyWrapper(); $record = new Record();
//standard field $record->addFieldValue(Contacts::LastName(), "Boyle");
//custom field $record->addKeyValue("Designation", "Accountant");
// custom picklist field $record->addKeyValue("Pick_List_2", new Choice("Option 1"));
//custom lookup field $lookup = new Record(); $lookup->addKeyValue("id", "5545974771087"); $record->addKeyValue("Lookup_1", $lookup);
//Standard picklist field $record->addFieldValue(Contacts::LeadSource(), new Choice("Advertisement"));
//Standard lookup field $lookup1 = new Record(); $lookup1->addKeyValue("id", "55459742674230"); $record->addFieldValue(Contacts::AccountName(), $lookup1);
//Owner lookup field $recordOwner = new User(); $record->addKeyValue("Owner", $recordOwner);
$bodyWrapper->setData([$record]);
$trigger = ["approval", "workflow", "blueprint"]; $bodyWrapper->setTrigger($trigger);
$headerInstance = new HeaderMap(); $response = $recordOperations->createRecords($moduleAPIName, $bodyWrapper, $headerInstance);
//Add code to handle the response received in $response.
// For more details, refer here. } } CreateRecords::initialize(); $moduleAPIName = "Contacts"; CreateRecords::createRecords1($moduleAPIName);
|
2. Multi-select Lookup Fields, Multi-select Picklist Fields and Multi-user Picklist Fields
2.1 Multi-select Lookup Fields
Use the following format to set or update Multi-select Lookup Fields while creating or updating a record.
$LookupVar1 = new Record(); $LookupVar1->addKeyValue("id", "lookup_record_id1"); $mslookupVariable1 = new Record(); $mslookupVariable1->addKeyValue("Field_API_Name", $LookupVar1); $LookupVar2 = new Record(); $LookupVar2->addKeyValue("id", "lookup_record_id2"); $mslookupVariable2 = new Record(); $mslookupVariable2->addKeyValue("Field_API_Name", $LookupVar2); $record->addKeyValue("Field_API_Name", [$mslookupVariable1, $mslookupVariable2]); |
2.2 Multi-select Picklist Fields
Use the following format to set or update Multi-select Picklist Fields while creating or updating a record.
$variable->addKeyValue("Picklist_Field_API_Name", [new Choice("Picklist_Value1"), new Choice("Picklist_Value2")]); |
2.3 Custom Multi-user Picklist Fields
To set or update a custom Multi-user Picklist Field, use the following format.
$lookupVar1 = new User(); $lookupVar1->addKeyValue("id", "user_id1"); $mulookupVariable1= new User(); $mulookupVariable1->addKeyValue("Field_API_Name", $lookupVar1); $lookupVar2 = new User(); $lookupVar2->addKeyValue("id", "user_id2"); $mulookupVariable2= new User(); $mulookupVariable2->addKeyValue("Field_API_Name", $lookupVar2); $record->addKeyValue("Field_API_Name", [$mulookupVariable1, $mulookupVariable2]); |
Here is a sample code to create a record in Contacts module with the above field types.
<?php use com\zoho\crm\api\HeaderMap; use com\zoho\crm\api\record\BodyWrapper; use com\zoho\crm\api\record\RecordOperations; use com\zoho\crm\api\record\Contacts; use com\zoho\crm\api\util\Choice; use com\zoho\crm\api\users\User; use com\zoho\crm\api\record\Record; require_once "vendor/autoload.php";
class CreateRecords { public static function initialize() { // add initialisation code // refer to the previous post for details and examples }
public static function createRecords1(string $moduleAPIName) { $recordOperations = new RecordOperations(); $bodyWrapper = new BodyWrapper(); $record = new Record();
$record->addFieldValue(Contacts::LastName(), "Boyle");
// custom multi-picklist $record->addKeyValue("Event_Participation", [new Choice("Webinar"), new Choice("Trade Show")]);
//custom multi-lookup $lookup1 = new Record(); $lookup1->addKeyValue("id", "5545974471152"); $multiSelectLookup1 = new Record(); $multiSelectLookup1->addKeyValue("Products", $lookup1);
$lookup2 = new Record(); $lookup2->addKeyValue("id", "554597771087"); $multiSelectLookup2 = new Record(); $multiSelectLookup2->addKeyValue("Products", $lookup2); $record->addKeyValue("Products", [$multiSelectLookup1, $multiSelectLookup2]);
//multi-user lookup $userlookup1 = new User(); $userlookup1->addKeyValue("id", "5545974393001"); $multiUserLookup1 = new User(); $multiUserLookup1->addKeyValue("Sales_Reps", $userlookup1);
$userlookup2 = new User(); $userlookup2->addKeyValue("id", "5545974492072"); $multiUserLookup2 = new User(); $multiUserLookup2->addKeyValue("Sales_Reps", $userlookup2); $record->addKeyValue("Sales_Reps", [$multiUserLookup1, $multiUserLookup2]); $bodyWrapper->setData([$record]); $headerInstance = new HeaderMap(); $response = $recordOperations->createRecords($moduleAPIName, $bodyWrapper, $headerInstance); //Add code to handle the response received in $response
// For more details, refer here. } }
CreateRecords::initialize(); $moduleAPIName = "Contacts"; CreateRecords::createRecords1($moduleAPIName);
|
3. Updating Related Records using External ID
For Related Records using External ID, define the external id information in the header as follows:
$xExternal = "Module.External_ID_Field_Name,Related_Module.External_ID_Field_Name"; $relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName, $moduleAPIName, $xExternal); |
Here is a sample code for linking the products with External_Product_ID (External ID field) PR01 and PR02 with a Lead with External_ID (External ID field) ABC123.
<?php use com\zoho\crm\api\relatedrecords\BodyWrapper; use com\zoho\crm\api\relatedrecords\RelatedRecordsOperations; use com\zoho\crm\api\record\Record; require_once "vendor/autoload.php";
class UpdateRelatedRecordsUsingExternalId { public static function initialize() { // add initialisation code // refer to the previous post for details and examples }
public static function updateRelatedRecordsUsingExternalId1(string $moduleAPIName, string $externalValue, string $relatedListAPIName) { $xExternal = "Leads.External_ID,Products.External_Product_ID"; $relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName, $moduleAPIName, $xExternal); $request = new BodyWrapper();
$record1 = new Record(); $record1->addKeyValue("External_Product_ID", "PR01");
$record2 = new Record(); $record2->addKeyValue("External_Product_ID", "PR02");
$request->setData([$record1, $record2]); $response = $relatedRecordsOperations->updateRelatedRecordsUsingExternalId($externalValue, $request); //Add your code to handle the response received in $response
//For more details, refer here. } } UpdateRelatedRecordsUsingExternalId::initialize(); $moduleAPIName = "Leads"; $externalValue = "ABC123"; $relatedListAPIName = "Products"; UpdateRelatedRecordsUsingExternalId::updateRelatedRecordsUsingExternalId1($moduleAPIName, $externalValue, $relatedListAPIName);
|
4. Uploading a file to the ZFS
You can upload a file to the ZFS directly using the absolute file path, or you can stream the file from external source using their APIs. Depending on the method, the StreamWrapper class initialisation arguments differs.
If you are using the stream method, use the filename and stream that you obtain from the external source's API response.
$streamWrapper = new StreamWrapper(filename, stream, null); |
If you want to use the absolute file path, the first two arguments should be null, and provide the file path as the third argument.
$streamWrapper = new StreamWrapper(null, null, "provide_file_path_here"); |
Here is a sample code to upload a file to ZFS from the local drive using the second method.
<?php use com\zoho\crm\api\ParameterMap; use com\zoho\crm\api\file\BodyWrapper; use com\zoho\crm\api\file\FileOperations; use com\zoho\crm\api\util\StreamWrapper; require_once "vendor/autoload.php";
class UploadFiles { public static function initialize() { // add initialisation code // refer to the previous post for details and examples }
public static function uploadFiles1() { $fileOperations = new FileOperations(); $bodyWrapper = new BodyWrapper(); $streamWrapper = new StreamWrapper(null, null, "/Users/user-1/Downloads/zoho.png"); $bodyWrapper->setFile([$streamWrapper]); $paramInstance = new ParameterMap(); $response = $fileOperations->uploadFiles($bodyWrapper, $paramInstance); //Add your code to handle the response received in $response
//For more details, refer here. } }
UploadFiles::initialize(); UploadFiles::uploadFiles1();
|
If successful, the $response object would contain the file id.
5. File Upload Field and Image Upload Field
To upload an image to an image upload field, or a file to a file upload field, you must first upload the file to ZFS using methods described in section 4. Use the id from the response to upload to the respective field.
Here is a sample code to upload an image and a file to a image upload field and file upload field respectively, in Leads module.
<?php use com\zoho\crm\api\HeaderMap; use com\zoho\crm\api\record\BodyWrapper; use com\zoho\crm\api\record\FileDetails; use com\zoho\crm\api\record\RecordOperations; use com\zoho\crm\api\record\ { Leads }; use com\zoho\crm\api\record\ImageUpload; use com\zoho\crm\api\record\Record; require_once "vendor/autoload.php";
class CreateRecords { public static function initialize() { // add initialisation code // refer to the previous post for details and examples }
public static function createRecords1(string $moduleAPIName) { $recordOperations = new RecordOperations(); $bodyWrapper = new BodyWrapper();
$record = new Record(); $record->addFieldValue(Leads::LastName(), "Boyle"); $record->addFieldValue(Leads::FirstName(), "Patricia"); $record->addFieldValue(Leads::Company(), "Zylker Corp"); $imageUpload = new ImageUpload(); $imageUpload->setEncryptedId("39c17f1033cd120e62f8104c5450213ede77147fe6"); $record->addKeyValue("Image_Upload", [$imageUpload]);
$fileDetail = new FileDetails(); $fileDetail->setFileId("39c17f1033cd120e62f8104c545af0efea6cc3c67cabefb16"); $record->addKeyValue("File_Upload", [$fileDetail]);
$headerInstance = new HeaderMap();
$bodyWrapper->setData([$record]);
$response = $recordOperations->createRecords($moduleAPIName, $bodyWrapper, $headerInstance); //Add your code to handle the response received in $response
// For more details, refer here. } } CreateRecords::initialize(); $moduleAPIName = "Leads"; CreateRecords::createRecords1($moduleAPIName); |
We hope that you found this post useful. Stay tuned for more of these!
If you have any questions, let us know in the comments below, or write to us at
support@zohocrm.com. We would love to hear from you!
See you next week with more useful content.
Cheers!
Recent Topics
Deluge sendmail in Zoho Desk schedule can't send email from a verified email address
I am trying to add a scheduled action with ZDesk using a Deluge function that sends a weekly email to specific ticket client contacts I've already verified the email address for use in ZDesk, but sendmail won't allow it in its "from:" clause. I've attached
Zoho Learn & Zoho Connect
Hi, Is there a way to sync the knowledge base we have in Zoho Learn with the manuals section is Zoho Connect? Thanks,
Addin Support in Zoho Sheet
Is there any addin support available in zoho sheet as like google marketplace to enhance productivity by connecting with other apps, providing AI data analysis, streamlining business processes, and more?
Changing Corporate Structure - How Best to Adapt Current and Future Zoho Instances
My current company is Company A LLC with a dba ("doing business as" - essentially an alias) Product Name B. Basically, Company A is the legal entity and Product Name B is what customers see, but it's all one business right now. We currently have a Zoho
how to add subform over sigma in the CRM
my new module don't have any subform available any way to add this from sigma or from the crm
{"errors":[{"id":"500","title":"Servlet execution threw an exception"}]}
Here's the call to move a file to trash. The resource_id is accurate and the file is present. header = Map(); header.put("Accept","application/vnd.api+json"); data = Map(); data_param1 = Map(); att_param1 = Map(); att_param1.put("status",51); data_param1.put("attributes",att_param1);
How to Install Zoho Workdrive Desktop Sync for Ubuntu?
Hi. I am newbie to Linux / Ubuntu. I downloaded a tar.gz file from Workdrive for installing the Workdrive Desktop Sync tool. Can someone give me step by step guide on how to install this on Ubuntu? I am using Ubuntu 19.04. Regards Senthil
Integración Books para cumplir la ley Crea y Crece y Ley Antifraude (VeriFactu)
Hola: En principio, en julio de 2025, entra en vigor la ley Crea y Crece y Ley Antifraude (VeriFactu). ¿Sabéis si Zoho va a cumplir con la ley para cumplir con la facturación electrónica conectada a Hacienda? Gracias
How to upload own video?
How can you upload your own video on your zoho website? I do not want to use another host, but i want to insert my own files. how can i do this?
Support new line in CRM Multiline text field display in Zoho Deluge
Hi brainstrust, We have a Zoho CRM field which is a Muti Line (Small) field. It has data in it that has a carriage return after each line: When I pull that data in via Deluge, it displays as: I'm hoping a way I can change it from: Freehand : ENABLED Chenille
A couple of minor enhancements to Workflows
Last updated on September 17, 2024: These enhancements were initially available for early access, and we've now enabled them for all users. We are elated to announce a couple of enhancements to custom functions in our Workflows! Say hello to: "Source"
Announcing new features in Trident for Windows (v.1.32.5.0)
Hello Community! Trident for Windows just got better! This update includes new features designed to improve and simplify email and calendar management—and it includes a feature you’ve been waiting for. Let’s dive into what’s new! Save emails in EML or
How to render either thumbnail_url or preview_url or preview_data_url
I get 401 Unauthorised when using these urls in the <img> tag src attribute. Guide me on how to use them!
Zoho CRM Calendar | Custom Buttons
I'm working with my sales team to make our scheduling process easier for our team. We primary rely on Zoho CRM calendar to organize our events for our sales team. I was wondering if there is a way to add custom button in the Calendar view on events/meeting
Option to Empty Entire Mailbox or Folder in Zoho Mail
Hello Zoho Mail Team, How are you? We would like to request an enhancement to Zoho Mail that would allow administrators and users to quickly clear out entire folders or mailboxes, including shared mailboxes. Current Limitation: At present, Zoho Mail only
Default Sorting on Related Lists
Is it possible to set the default sorting options on the related lists. For example on the Contact Details view I have related lists for activities, emails, products cases, notes etc... currently: Activities 'created date' newest first Emails - 'created
Directly Edit, Filter, and Sort Subforms on the Details Page
Hello everyone, As you know, subforms allow you to associate multiple line items with a single record, greatly enhancing your data organization. For example, a sales order subform neatly lists all products, their quantities, amounts, and other relevant
Create custom rollup summary fields in Zoho CRM
Hello everyone, In Zoho CRM, rollup summary fields have been essential tools for summarizing data across related records and enabling users to gain quick insights without having to jump across modules. Previously, only predefined summary functions were
Create static subforms in Zoho CRM: streamline data entry with pre-defined values
Last modified on (9 July, 2025): This feature was available in early access and is currently being rolled out to customers in phases. Currently available for users in the the AU, CA, and SA DCs. It will be enabled for the remaining DCs in the next couple
Create Lead Button in Zoho CRM Dashboard
Right now to create Leads in the CRM our team is going into the Lead module, selecting the "Create Lead" button, then building out the lead. Is there anyway to add the "Create Lead" button or some sort of short cut to the Zoho CRM Dashboard to cut out
Searching customer field
Hello, When entering a receipt, we select customer information. The customer information is synced with Zoho CRM. However, we can't find the customer information because it searches for words that begin with the entered value. It needs to search for words
Introducing Version-3 APIs - Explore New APIs & Enhancements
Happy to announce the release of Version 3 (V3) APIs with an easy to use interface, new APIs, and more examples to help you understand and access the APIs better. V3 APIs can be accessed through our new link, where you can explore our complete documentation,
stock
bom/bse : stock details or price =STOCK(C14;"price") not showing issue is #N/A! kindly resolve this problem
Rotate an Image in Workdrive Image Editor
I don't know if I'm just missing something, but my team needs a way to rotate images in Workdrive and save them at that new orientation. For example one of our ground crew members will take photos of job sites vertically (9:16) on his phone and upload
Improved RingCentral Integration
We’d like to request an enhancement to the current RingCentral integration with Zoho. RingCentral now automatically generates call transcripts and AI-based call summaries (AI Notes) for each call, which are extremely helpful for support and sales teams.
Resume Harvester: New Enhancements for Faster Sourcing
We’re excited to share a set of enhancements to Resume Harvester that make sourcing faster and more flexible. These updates help you cut down on repetitive steps, manage auto searches more efficiently, and review candidate profiles with ease. Why we built
Using Zoho Flow to create sales orders from won deal in Zoho CRM
Hi there, We are using Zoho Flow to create sales orders automatically when a deal is won in Zoho CRM. However, the sales order requires "Product Details" to be passed in "jsonobject", and is resulting in this error: Zoho CRM says "Invalid input for invalid
WIDGET in related record list ZOHO CRM; how to get and put data to subform custom fields?
he need: Read and write two custom subform line-item fields on Quotes: Segment_wyceny (picklist/text) and W_pakiecie (number). Write works; read does not return these fields via SDK. Environment Zoho CRM Widget Zoho Embedded App SDK v1.2 Module: Quotes
Cliq iOS can't see shared screen
Hello, I had this morning a video call with a colleague. She is using Cliq Desktop MacOS and wanted to share her screen with me. I'm on iPad. I noticed, while she shared her screen, I could only see her video, but not the shared screen... Does Cliq iOS is able to display shared screen, or is it somewhere else to be found ? Regards
Zoho CRM Tracking Google Enhanced Conversions
Can anyone @Zoho, consultants, or users help me understand if Zoho CRM is going to support Google's Enhanced Conversions? I included some information from Google below about it. We use Google Adwords for our pay per click advertising for lead generation,
zoho click, and nord VPN
Unfortunately, we've been having problems with Zoho Click, where essentially the line cuts off after about a minute's worth of conversation every time we are on VPN. Is there a way we can change this within the settings so it does not cut the line off
Recurring Supervisor Rule Reminders for Open/In-Progress Tickets
Hello Zoho Support Team, I would like to suggest a potential improvement regarding reminders for tickets and activities in Zoho Desk. Currently, it is possible to set reminders only once. In the Supervisor Rules section, it is possible to configure reminders
Connecting Portals from different Zoho apps
Hi, I note that Zoho has functionality for customer portals for several of the Zoho apps, like CRM, Projects, Desk etc. Is there any way to connect these portals? It would be great if we could give our customers access to a portal in which they could
Billing Management: #5 Usage Billing
After understanding the nuances of Advance Billing and Retainers, we will explore one of the booming billing models. Long ago, villagers drew water from a shared well in a small village. The well was a lifeline for the entire community. Ravi, the well
Function #10: Update item prices automatically based on the last transaction created
In businesses, item prices are not always fixed and can fluctuate due to various factors. If you find yourself manually adjusting the item rates every time they change, we have the ideal time-saving solution for you. In today's post, we bring you custom
Inventory Adjustments
Hi, How to transfer the material from one head to another ? Like materials purchased for manufacturing the laptop need to transfer from consumption inventory (Quantity of raw materials reduced) to destination inventory ( Quantity of Laptop increased)
Zoho CRM Community Digest - Aug 2025 | Part 1
Hey everyone! The first half of August went by, and we have a few announcements and some good noteworthy discussions. So, let's take a look at them! Product Updates: Introducing Connected Records feature: Zoho CRM’s Next-Gen UI now includes Connected
Problems with email templates (HTML - Outlook)
Hi there, I've been trying to create a newsletter from the template "Business 4". Everything looks great in the preview, but when I send it to my Outlook inbox, the layout doesn't seems to stick. More particularly: - The line-height is way more reduced, even though I used the line-height tool from the template - Columns but they are sometimes misaligned - Font size is not always the one I've selected. Could you help? Thanks!
Please make it easier to Pause syncing
right now it takes 3 clicks to get there. sounds silly, but can you make it just 2 clicks to get it done instead? thats how dropbox does it, 2 clicks to pause instead of 3.
How to create a Zoho CRM report with 2 child modules
Hi all, Is it possible to create a Zoho CRM report or chart with 2 child modules? After I add the first child module, the + button only adds another parent module. It won't let me add multiple child modules at once. We don't have Zoho Analytics and would
Next Page