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
equest to Disassociate Bigin from Zoho One and Migrate to Standalone (Upgrade to Bigin Premier – 3 Seats, Annual)
Dear Zoho One Support Team, I’m writing to request your assistance to disassociate (remove) the Bigin application from our Zoho One organization while preserving all existing Bigin data. After the disconnection is successfully completed, we intend to
SMTP email sending problem
Hello, I've sent emails before, but you haven't responded. Please respond. My work is being disrupted. I can't send emails via SMTP. Initially, there were no problems, but now I'm constantly receiving 550 bounce errors. I can't use the service I paid
billing
hi, I am being billed $12/year, and I can't remember why. My User ID is 691273115 Thanks for your help, --Kitty Pearl
How to add receipts
How to add receipts
Unable to enable tax checkboxes
Hi Zoho Commerce Support, I'm writing to report an issue I'm having with the tax settings in my Zoho Commerce store. I've created several tax rates under Settings > Taxes, but all of them appear with the checkbox disabled. When I try to enable a checkbox,
Zoho Commerce - Enable Company Name and Tax Number collection for B2B orders in Global Edition
Please enable Company Name and Tax Details option on checkout settings in Zoho Commerce Global Edition. It is still important to collect Company Name and Tax Number for B2B sales in many countries. My business is based in Ireland (in the EU) and I have
ZohoSign and ZohoBooks Integration/Workflow
Hello All, We utilize ZohoSign for signatures on tax eFiles. We utilize Dynamic KBA. Additionally, we use ZohoBooks for invoicing for these services. Is there a way to accomplish the following: Send a copy of the Tax Return, Invoice and eFiles in one
Manage monthly tasks with projectsf
Hi All I run a finance and operations team where we need both teams to complete monthly tasks to ensure we hit our deadlines. Can Zoho projects be used for this. There many finance focused tools but we have Zoho one so want to explore Thanks Will
Zoho Suite is very slow
Since today Zoho is incredibly slow over all applications! What's going on?
How can I track which zoho users are actively using Zoho CRM
I have several licenses of Zoho CRM. We now need to add a new user. I could purchase a new license, but before I do, I would like to see if any of our existing users are not actively using the license assigned to them. How can I determine the activity
Is anyone else having trouble saving a custom image in their email signature, or is it just me?
When I try to save the image I get an error that says "Operation Failed" I opened a support ticket two weeks ago and received a response that it would be debugged, but it still isn’t working
Combine and hide invoice lines
In quickbooks we are able to create a invoice line that combines and hides invoices lines below. eg. Brochure design $1000 (total of lines below, the client can see this line) Graphic Design $600 (hidden but entered to reporting and
Transaction Locking with the dynamic date
Is it possible to dynamically update dates on transaction locking. We want to lock transaction x days from today
Zoho Devops
We have a Zoho one account which we have integrated with an SAS educational product, sold on a subscription model, using webhooks and API calls. We make some use of custom fields and cross module lookups and relationships. We utilize CRM, Books and billing
Fuel up your sales with the Zoho SalesIQ + Bigin integration
Hi everyone! We’re happy to bring you the all-new Zoho SalesIQ + Bigin integration. With this, every prospect from your website instantly becomes a contact in Bigin, complete with transcripts and follow-up tasks, so you never lose a lead again. Let's
Introducing AI-powered Assessments & Zoho's native LLM, Zia
We’ve shipped a cleaner, faster way to create assessments in Zoho Recruit. 🚀 Instead of manually building question banks or copying old templates, you can now generate ready-to-use assessments in just a few clicks, all tailored to the role you’re hiring
Ability to Reset Visitor Fields During an Active Chat Flow
Hello Zoho SalesIQ Team, We hope you are doing well. We would like to propose a feature enhancement to Zoho SalesIQ regarding the management of visitor fields within Zobot flows. Use Case: Our bot asks the visitor to provide information about a 3rd person
External ID in Zoho CRM
Hello everyone! We know that Zoho CRM allows you to integrate third-party apps and manipulate data through APIs. While you integrate a third-party application, you may want to store the third-party reference IDs in Zoho CRM's records. To meet this need
Some emails are not being delivered
I have this problem where some of my mail just seems to disappear. When I send it, it appears as sent with no mention of any problem, but my recipient never gets it, not even in the Spam folder. Same for receiving, I have a secondary e-mail address, and
New in Zoho Chat : Search for contacts, files, links & conversations with the all new powerful 'Smart Search' bar.
With the newly revamped 'Smart Search' bar in Zoho Chat, we have made your search for contacts, chats, files and links super quick and easy using Search Quantifiers. Search for a contact or specific conversations using quantifiers, such as, from: @user_name - to find chats or channel conversations received from a specific user. to: @user_name - to find chats or channel conversations sent to a specific user. in: #channel_name - to find a particular instance in a channel. in: #chat_name - to find
Template modifiactions
Hello, I am struggling with the templates in ZOHO Books. Especially with the placement of some items, like company address, ship to, bill to etc. For example: One item I like from template X (placement of ship to and bill to next to each other in the
Aggregating the First Value in the Group By of a dataset
Hi I am trying to get the following Aggregate Formula to work in my chart, but cannot seem to get the right format. I have a series of data that I am running an include_groupby and want to SUM only a column in the first row of each group. So for example.
Admin Control Over Profile Picture Visibility in Zoho One
Hello Zoho Team, We hope you are doing well. Currently, as per Zoho’s design, each user can manage the visibility of their profile picture from their own Zoho Accounts page: accounts.zoho.com → Personal Information → Profile Picture → Profile Picture
Track Zoho Campaign and Workflow sales impact
I am attempting to measure the performance of our marketing workflows and campaigns by comparing the date each campaign was sent to a contact with the purchase date of the contact. For example, if Contact A was sent Email A on 9/1 and made a purchase
Tables for Europe Datacenter customers?
It's been over a year now for the launch of Zoho Tables - and still not available für EU DC customers. When will it be available?
What is a line break code for zoho?
Hi, I am archiving data by adding values from a single line field from one form to a multi-line field in another form. So I need a code/function that starts a new line on that multi-line field so it does not just keep adding it on the same line. Example, doing something like this means that it will be on a same line. archive.field1 = archive.field1 + input.Field1 I need a code so the input.Field1 can just start on the next line. Instead of "value 1, 2,3,4,5" It will be: "1 2 3 4 etc.". something
Automatic Project Owner change
Is there a way to change Project Owner automatically once a specific Milestone in a project is marked as completed. Different Teams are working on projects in our Org, they have their own Milestones to complete and so we transfer the project from team
Button to add product to cart
Is there a way to have a button on a page, that when clicked, will add Qty 1 of a product to the cart?
Problem with Submit Button Design
I have made a template to apply to my forms and under the button controls, I have it set to "standard" and yet it's still filling the container. This is super frustrating and looks weird. Why do we not have full control over button size? How can I fix
Zoho CRM- Authorize your Microsoft Teams account issue
Hi, I tried to link Zoho CRM with Teams and I got the following message: Clicking "Authorize now" sent me to the following page, Microsoft tried to start a session but, after 3 seconds the page closed and nothing happened. I get the same message each
Passing the CRM
Hi, I am hoping someone can help. I have a zoho form that has a CRM lookup field. I was hoping to send this to my publicly to clients via a text message and the form then attaches the signed form back to the custom module. This work absolutely fine when
Is there a way to associate an email in ZOHO Main to a Vendor record in ZOHO CRM
My situation is as below, I have a vendor in ZOHO CRM lets say "Vend A" and an associated contact, "Cont A" If Cont A sends me an email using the email I've registered in the contact record the standard OOTB email sync will work. But the vendor has some
Bank charges are applied. Please select a bank account.
Hello, I'm trying to add bank charges to a customer payment, but I get the error message "Bank charges are applied. Please select a bank account." I found this old thread, where it says that I need to "select a Bank account for the 'Deposit To' dropdown
Kaizen #207 - Answering your Questions | Advanced Queries using COQL API
Hi everyone, and welcome to another Kaizen week! As part of Kaizen #200 milestone, many of you shared topics you would like us to cover, and we have been addressing them one by one over the past few weeks. Today, we are picking up one of those requests
Présentation de SecureForms dans Zoho Vault
Soyons francs : demander à quelqu’un de transmettre un mot de passe ou des informations sensibles n’est jamais une tâche facile. On attend, on relance, parfois de nombreuses fois. Et quand l’information arrive, elle se retrouve souvent dispersée dans
Introducing Connected Records to bring business context to every aspect of your work in Zoho CRM for Everyone
Hello Everyone, We are excited to unveil phase one of a powerful enhancement to CRM for Everyone - Connected Records, available only in CRM's Nextgen UI. With CRM for Everyone, businesses can onboard all customer-facing teams onto the CRM platform to
Granular Email Forwarding Controls in Zoho Mail (Admin Console and Zoho One)
Hello Zoho Mail Team, How are you? At present, the Zoho Mail Admin Console allows administrators to configure email forwarding for an entire mailbox, forwarding all incoming emails to another address. This is helpful for delegation or backup purposes,
Sales order & purchase order item links for item details
This is fantastic for checking lots of things, I use it a lot. It would be great to see it extended to invoices & bills On another note, may as well throw in my favourite whinge ..... Wish you guys would get the PO receive differences sorted urgently,
Zoho Workdrive - Communication / Chat Bar
Hi Team, Please consider adding an option to allow admins to turn on or off the Zoho Communication Bar. Example of what I mean by Communication Bar: It's such a pain sometimes when I'm in WorkDrive and I want to share a link to a file with a colleague
Kaizen #190 - Queries in Custom Related Lists
Hello everyone! Welcome back to another week of Kaizen! This week, we will discuss yet another interesting enhancement to Queries. As you all know, Queries allow you to dynamically retrieve data from CRM as well as third-party services directly within
Next Page