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
Time Entry Notifications
Hi All - I have support staff who place notes of their work in the time entry section of Zoho Desk. Is there a specific workflow or setting I need to enable to have the ticket holder updated via email when an entry is saved?
How to report 'Response violation' OR 'Resolution violation'
Hi, I want to report on SLA Violation Type. I grouped my tickets on this column. It seems I only get 'Response and Resolution Violation' or 'Not Violated'. The former seems to be given to a ticket if only the Response Time was violated. I would expect
[Webinar] Automate sales and presales workflows with Writer
Sales involves sharing a wide range of documents with customers across the presales, sales, and post-sales stages: NDAs, quotes, invoices, sales orders, and delivery paperwork. Generating and managing these documents manually slows down the overall sales
Power of Automation :: Quick way to associate your Projects with Zoho CRM
A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate complex tasks and
Date triggering Workflow rule
I have a function triggered by a workflow rule. The function takes a date and creates a task for that date and fills in a field with the name of the day for that date. It also updates the status field of the record. The workflow rule is set to run whenever
Restricting contact creation
Hi all! I am looking to use Zoho Desk in a part of the business that takes end user enquiries. These are generally single interactions, and not linked to an account name. As Desk is Account centric, has anyone designed a way to manage these incoming emails
Import Holiday Calendars
HI Zoho Is there anyway of importing an online calendar like https://www.calendarlabs.com into the business hours calendars, to speed up setup of holiday calendars. Also could we also request a feature where you can specify a Holiday as hours, i.e it could be that the company is on a 1/2 day due to a holiday or when it is Eid in the UAE and they are only allowed to work restricted hours so we need the calendar to be flexible to allow for this. Regards Jamie
Filtering Tickets based on Email headers
We're starting to get a lot more junk coming into our Zoho Desk, which is then triggering unnecessary email alerts to agents. Once thing we could do to cut this junk in half, is to filter tickets based on email headers. Any email containing the `List-Unsubscribe`
Error 550 5.4.1
I’ve tried sending an email to someone but keep receiving this back. Any help would be greatly appreciated
Billing Management: #2 Fair way of Billing- Prorated Billing
Hello, From speaking about the traditional ways of billing in the previous post, we are moving into the deep sea of billing. We are now in a zone to break out the most complex yet, I would call it the fairest way of billing, the Prorated Billing. Prorated
Has Anyone successfully integrated Zoho and Sage Intact?
Hey all, We’re evaluating Zoho One + Sage Intacct and I’m trying to connect with anyone who has actually implemented the two together.Specifically, I’d love to know: -- Which functions you kept in Zoho vs. Intacct (e.g., Product Catalog, AR/AP, invoicing,
How can I filter a field integration?
Hi, I have a field integration from CRM "Products" in a form, and I have three product Categories in CRM. I only need to see Products of a category. Thanks for you answers.
Adding image in HTML report page
Hi, I want to know two things: 1. Can anyone advise how to add an image in HTML report. The tagged used is <img> but what path do I mention for the image to be added in the HTML report. 2. Also, I want to know if I am creating an application for the market
How to change view of HTML report based on device but always print in A4
Hello everyone, I am aware that HTML report view can be configured to adjust according to the screen size like Laptop, Tablet and mobile using media queries. But my concern is no matter on which device the reports is opened when printed should always
Age Calculation
I've attempted to calculate the age of someone based on their birthday input by using the formula field. It works but I don't want all those decimals on there. I then tried to use "set variable" after birthday input but I get a field type mismatch, long vs. floating. Any ideas would be wonderful.
Search on Custom Field
We're working on an integration with the Zoho FSM API and are trying to retrieve companies based on a custom field we added to the Companies module. However, we can't find a way to filter or query records using custom fields through the API. We have a
Sendmail function / custom action?
I've setup a function hoping to email various business departments the details of a record once all work in that record is complete so gone about setting up a custom action in such way that each record line on the report has a button to click. Question is how do I actually include data from that record in the email that is sent when the button is clicked? I had thought that since this were being sent per record the email would include the data which had been entered
API to post drafts for social media
I we want to post draft posts to our zoho social account and then approve and schedule them within Zoho social. is this possible with for example: https://apis.zoho.com/social/v2/post TIA Jon
Canvas View in Zoho Recruit
Is it possible or would it be possible to have the new 'Canvas View' in Zoho Recruit?
What impactful sales coaching techniques have you used to boost your team's performance?
I'm curious about the real-world impact of sales coaching on team performance. What specific techniques or strategies have you found most effective in driving consistent improvement and growth in your sales team? Any success stories or lessons learned
Adding Taxes to paid consultations in Zoho Bookings
I created a 'paid' consultation under Zoho Booking and integrated it with payment gateways for online/instant payment before a booking is done. How can I add 'taxes' to the price of consultation? I can add taxes to other Zoho apps (liks Books, Checkout,
Zoho Finance Suite - Customer Custom Tabs - Dynamic Link
Hi Finance Suite team, When creating a Custom Tab for a Client Portal, there is no option to add dynamic parameters. This would be very helpful for adding Zoho Analytics dashboards which can be dynamically filtered through the URL to only show information
Possible to bold or indent text in the description field?
As part of one item, I often have a detailed description that would be much easier to read if there was the ability to have a bulleted list or bold text and the like. Is this possible? My last invoicing software allowed markup in the field so, for example, an asterisk meant a bullet. I haven't been able to find any documentation related to this. Any information would be appreciated. Thank you.
How can I setup Zoho MCP with Chat GPT
I can set up custom connections with Chat GPT but I cat an error when I try to set it up. The error is: "This MCP server can't be used by ChatGPT to search information because it doesn't implement our specification: search action not found" Thoughts?
Formatting of Balance Sheet and Profit & Loss Reports
The default format of the Balance Sheet and P&L Reports are based on the Account Types and then the individual accounts within the Chart of Accounts. These are then ordered alphabetically under these sub-headings and one is unable to re-order these or
UK MTD reports concerning turnover and cerash accounting
Hi I am a sole trader, and I have just started with Zoho Books in order to comply with the new HMRC requirements. I use 'cash basis' - which I understand to mean that income is when the cash comes in (not the invoice date) and expenses are when they are
Retainer Invoice.
Why ZOHO not have facilities to deduct partially advance payment from an invoice.
IMAP Server not responding.
Trying to connect a phone via IMAP and getting "imap.zoho.com not responding." Is the server down, for maintenance or otherwise? I've tried this on two different devices and got the same error on both.
Share saved filters between others
Hi, I am in charge to setup all zoho system in our company. I am preparing saved filters for everybody, but the only one can see its me. How can others see it? Thanks
GST Slabs Redefined: Stay Compliant Using Zoho Books!
Hello Everyone! The Government of India is rolling out new GST rates, a major reform aimed at simplifying the current tax structure starting 22 September 2025. GST will move from four slabs (5%, 12%, 18%, 28%) to two main slabs (5% and 18%), plus a special
Kanban view on Zoho CRM mobile app!
What is Kanban? The name doesn't sound English, right? Yes, Kanban is a Japanese word which means 'Card you can see'. As per the meaning, Kanban in CRM is a type of list view in which the records will be displayed in cards and categorized under the given
Presenting ABM for Zoho CRM: Expand and retain your customers with precision
Picture this scenario: You're a growing SaaS company ready to launch a powerful business suite, and are looking to gain traction and momentum. But as a business with a tight budget, you know acquiring new customers is slow, expensive, and often delivers
No practical examples of how survey data is analyzed
There are no examples of analysis with analytics of zoho survey data. Only survey meta data is analyzed, such as number of completes, not actual analysis of responses, such as the % in each gender, cross-tabulations of survey responses. One strange characteristic
Zoho Creator as LMS and Membership Solution
My client is interested in using Zoho One apps to deploy their membership academy offer. Zoho Creator was an option that came up in my research: Here are the components of the program/offer: 1. Membership portal - individual login credentials for each
Adding Chargebee as a Data Connector
Is it possible to get Chargebee added as a Zoho Analytics data connector?
Webform & spam
Hi, We set up 2 webform on our website, fowarding the content to Zoho CRM. Since it has been opened up, we are getting lot of spam message (for now about 20 a day). To lower the amount of false new leads we added the captcha field and new enquieries are send to the Approval Leads list. However we still get some spam. Is there any "anti spam" mechanism built in Zoho CRM, or how is the best way to avoid these kind of spam ? Thanks
Dropbox to Workdrive
Namaste, Trust you all are doing well. Wanted to check how this can be done with Zoho flow. I typically receive dropbox links from my clients. Is there a way where I can provide the link to Zoho flow and it downloads the files from dropbox link to a work
Deals by Stages Funnel not showing in correct order
Using the Stage-Probability Mapping for the Deals module we have created a steps our deals will pass through, RFQ, Closed/Lost, Declined/No-Go, Pricing, Submitted, Negotiations, Won. However when I view the Deal By Stages Funnel it does not show in the
Turning off the new UI
Tried the new 'enhanced' UI and actively dislike it. Anyone know how to revert back?
Confirmation prompt before a custom button action is triggered
Have you ever created a custom button and just hoped that you/your users are prompted first to confirm the action? Well, Zoho knows this concept. For example, in blueprint, whenever we want to advance to the next state by clicking the transition, it is
Next Page