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
Zoho Marketing Automation 2.0 - Landing Page function not working
Dear Zoho Team, I am working on implementing Zoho Marketing Automation 2.0, and am now looking into the section "Lead Generation". If I open the "Landing Pages" section, I immediately get an Error code: Error: internal error occurred. Can you help me
Zoho Mail Android app update: Manage folders
Hello everyone! In the latest version(v2.9) of the Zoho Mail Android app update, we have brought in support for an option to manage folders. You can now create, edit, and delete folders from within the mobile app. You can also manage folders for the POP
How to share ticket numbers across different ticket types
I'm running an event and have three different ticket types. Add on Event + Main Event - Early bird Main Event only - Early bird Add on Event only - Early bird And Standard class - shown but not available until early bird finishes Add on Event + Main Event
Adding Social Media Buttons to Basic Campaigns
Hi, I'm quote new to using Zoho Campaigns and I can't work out how to add Social Media Buttons into my basic campaign? In MailChimp there's a button that brings the icons into your campaign for you. I've tried adding the social media icons as 'buttons' in Zoho but it's not looking great. Can anyone help? Thanks!
Hide Inactive Social Sign-In Providers from Login Screen
Hello Zoho Team, We hope you are doing well. Currently, Zoho One allows admins to configure security policies and enable or disable Social Sign-In options for third-party providers such as Apple, Google, Microsoft, LinkedIn, Yahoo, Twitter, Facebook,
[Free Webinar] AI Agents in Zoho Creator - Creator Tech Connect
Hello Everyone! We welcome you all to the upcoming free webinar on the Creator Tech Connect Series. The Creator Tech Connect series is a free monthly webinar that runs for around 45 minutes. It comprises technical sessions in which we delve deep into
Download All Attached Files
It would be extremely useful to have "download-all" functionality for downloading files attached to a task, subtask, comment, forum post or hosted in the "Documents" section etc. We've instructed our users to zip multiple files prior to uploading, but of course they forget all the time. Having to download lots of files one-at-a-time off a comment or task wastes a lot of time.
unable to send message reason 554 5.1.8 Email outgoing blocked
unable to send message reason 554 5.1.8 Email outgoing blocked
Ship via Carrier Not Working Since Commerce Update
Since the recent update to the Commerce platform, I can no longer use the ship via carrier function. It will take me to the address screen and let me verify them but when I go to save and move tot he next screen it will not do anything. This is happening
automations: Can I execute a step on a specific date?
I have created a form in Zoho forms, and created a contacts list. I have also begun setting up an automation with the intention of sending the form to the contact list on a specific date every month (via email) for the entire year (essentially sending
Zoho Expense - The ability to add detail to a Trip during booking
As an admin, I would like the ability to add more detail to the approved Trips. At present a requestor can add flights, accommodation details and suggest their preferences. It would be great if the exact details of the trip could be added either by the
Adding Folders in Android App
Is it possible to create a new email folder within the Zoho Mail Android app? Or can this only be done from the desktop version of Zoho Mail? Cheers!
Schedule Exports for Regular Project Updates
Tracking project data often means exporting data at regular intervals. Instead of manually exporting data every time, users can schedule exports for Phases, Tasks, and Tasks in Zoho Projects. These exports can be set to run once, daily, weekly, or monthly
Question about custom fields using Pivot Tables.
I have created a pivot table showing annual revenue of a client and how much payment that client is paying my company. Is there a way using pivot table to add an additional field that subtracts those to fields / shows me a percentage of that difference?
Request for Light/Dark Mode
Would love the ability to switch between Light and Dark mode similar to Zoho CRM. https://help.zoho.com/portal/en/community/topic/introducing-dark-mode-light-mode-a-new-look-for-your-crm
Signature field is showing black
Hello, When customer signed the service form, it is showing as below picture Phone model: iPhone 16 Pro We tried delete and install application, but it not solved. This has on phone of a few person. There is any advice to solve this?
Journey Email - Ignored Contacts
I have a journey setup which simply sends a string of emails over time. For some reason I am getting large amounts of the contacts who enter the first email being ignored and I can't find anywhere in reports or audit logs why these contacts are not
Involved account types are not applicable when create journals
{
"journal_date": "2016-01-31",
"reference_number": "20160131",
"notes": "SimplePay Payroll",
"line_items": [{
"account_id": "538624000000035003",
"description": "Net Pay",
"amount": 26690.09,
"debit_or_credit": "credit"
}, {
"account_id": "538624000000000403",
"description": "Gross",
"amount": 32000,
"debit_or_credit": "debit"
}, {
"account_id": "538624000000000427",
"description": "CPP",
"amount": 1295.64,
"debit_or_credit": "debit"
}, {
"account_id": "538624000000000376",
"description":
Zoho Books - Include Payment Terms as a Custom View filter
It would be great if you could created a custom view based on Payment Terms. This would be really handy for seeing a list of customers who have credit terms. A workaround is not required. I could do something with a creditor checkbox, but it would be
How to update changed purchase account of item in invoice
I have selected the wrong purchase account for various articles and created invoices. I had to adjust the purchase account in the article afterwards, but the old purchase account is still posted in the transaction-journal of the invoice. To adjust the
Help - Zoho CRM notification on mobile (IOS/Android)
Hello Community! Can I get the IOS/Andoid CRM app to notify me of events, calls, etc. due as I can with MANY other apps? I am running the free Zoho I would like this to be native to the Zoho CRM app. I do not want to write a sep. mobile app
Zoho Books Idea - Include another field in Bank Details for Address
Hi Books team, Currently use the Description field in the Bank Details to store the bank's address. This works fine but it would be great if you could add another field for Bank Address, so that other notes about the bank account could be stored in the
a question about the COQL API v8
When I specify eight or more values in a WHERE IN clause and execute it, an error occurs. Is there a limit to the number of values that can be specified in a WHERE IN clause? ↓Error select * FROM Vendors WHERE (id in (1, 2, 3, 4, 5, 6, 7, 8, 9)) ↓Success
Zoho Books Idea - Bank Details Button on Banking
Hi Books team, Sometimes I'm asked to share bank details with a customer or a colleague. So I go to the Banking Module, find the correct bank account, click Setting > Edit, then copy and paste the bank details. Wouldn't it be great if there was a button
JS SDK 8.0 – TypeError: Cannot read properties of undefined (reading 'getCacheStore') with sample code
Hello Zoho Support Team, I’m integrating the Zoho CRM JavaScript SDK v8.0 and I’m getting the error below when running your official sample. I tested directly from: https://github.com/zoho/zohocrm-javascript-sdk-8.0/blob/main/samples/create_records_sample/create_records.js
Function #55: Convert multiple quotes to single SO using Custom Button
Hello everyone, and welcome back to our series! In Zoho Books, after a quote is accepted by your customer, it can be converted into a sales order or an invoice. Often, a customer might have multiple quotes, and for easier billing or upon the customer's
Time based workflow without edit/action
Hello I need help solving this problem if possible. We have Deals come into the CRM via Live Transfer which have the field properties: Stage = New Channel = Inbound Some of them don't get answered so we want these to automatically go into our Outbound
What's New - August 2025 | Zoho Backstage
Every month, Zoho Backstage grows with you. These updates aren't just features and fixes, they're about making your workday smoother, your events more impactful, and your attendees happier. We’ve listened, learned, and shaped this release to keep things
prevent selling expired items
Hello. I need to make a constraint on expired batch items not to be sold. Is it possible in Zoho Inventory? if so, then how? Thanks for further help.
Product details removed during update from other system
We maintain our product details in an other system. These details are synchronized with Zoho at the end of each day, through an API. This has worked perfectly sofar. But last Monday, all product codes and some other product data have been wiped during
Client Customer
I purchased a customer user license, but we cannot see the project I added in the customer account. I would like to ask for support on what we should do.
Add Ability to Use Zoho Finance Tags
For Zoho Finance (Books and Inventory), the current actions do not allow us to affect the tags associated with the entities in question (customers, vendors, items, etc.). Please consider adding this functionality into the actions.
Embeded Signing doesn't work on Safari Browser
We have implemented Zoho Sign in our website by using embeded signing, It works perfectly on Chrome. But it fails on Safari, We get stuck on Zoho Sign Page during redirection from Zoho Sign to our website after signing the document, Please let us know
Dataprep Webhook Limits and Cannot update column with Dataprep
I have two problems : 1 - I am using Airflow to trigger my pipeline, and when I tested it, it worked fine a couple of times. However, after that, I received an error: {"code":429,"message":"Request rate limited"}. I didn’t send too many requests — maybe
New in Zoho Forms: Google reCAPTCHA v3 for smarter spam protection
Hello form builders, Spam submissions are one of the biggest challenges when you share your forms online. They not only clutter your data but can also waste valuable time. To help you combat this without making life harder for genuine respondents, we’re
Project Management Bulletin: August, 2025
We’ve touched a grand 19 years since we started pioneering project management solutions with Zoho Projects. What started as a simple one-page interface is now a suite of products with Zoho BugTracker, Zoho Sprints, and our new debut Zoho Projects Plus,
Zoho Sign and Zoho Workdrive Integration
Hello, there. I want to know if it's possible to save a signed document from Zoho Sign in an specific folder for each signer in Zoho Workdrive. For example: If John Doe signs the document in Zoho Sign I want to save it automatically in a folder named
How do you list multiple contacts for a lead?
My sales team wants to be able to add additional contacts for leads, how do we do that? Is there a different way we should be using the lead / contact functionality? Moderation update (9th September 2025): Our developers have built an extension to achieve
Modifying Three Dot Menu Options
Is there a way to modify the three dot menu options that display in a Report header? They currently display: Show As (List, Calendar, Timeline), Print, Import, Export. I'd like to remove the Show As and Print options, since they aren't applicable for
Field Not Updating in FSM Script - Service and Parts module.
Dear Team, I am reaching out regarding a script I have implemented in Zoho FSM to automate the calculation of the End of Service date based on the End of Sale date in the Service and Parts module. Overview of the script: Fetches the End_of_Sale__C and
Next Page