Skip to product menu
Skip to main content

PHP SDK Samples - Custom View Operations

Get Custom views
              
              
<?php
namespace com\zoho\crm\sample\customview;
use com\zoho\crm\api\customviews\APIException;
use com\zoho\crm\api\customviews\CustomViewsOperations;
use com\zoho\crm\api\customviews\ResponseWrapper;
class CustomView
{
    /**
     * Get CustomViews
     * This method is used to get the custom views data of a particular module.
     * Specify the module name in your API request whose custom view data you want to retrieve.
     * @param moduleAPIName - Specify the API name of the required module.
     * @throws Exception
     */
    public static function getCustomViews(string $moduleAPIName)
    {
        //example
        //$moduleAPIName = "Leads";
        
        //Get instance of CustomViewOperations Class that takes moduleAPIName as parameter
        $customViewsOperations = new CustomViewsOperations($moduleAPIName);
        
        //Call getCustomViews method
        $response = $customViewsOperations->getCustomViews();
        
        if($response != null)
        {
            //Get the status code from response
            echo("Status code " . $response->getStatusCode() . "\n");

            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");

                return;
            }
            
            //Get object from response
            $responseHandler = $response->getObject();
                
            if($responseHandler instanceof ResponseWrapper)
            {
                //Get the received ResponseWrapper instance
                $responseWrapper = $responseHandler;
                
                //Get the list of obtained CustomView instances
                $customViews = $responseWrapper->getCustomViews();
            
                foreach($customViews as $customView)
                {
                    //Get the DisplayValue of each CustomView
                    echo("CustomView DisplayValue: " . $customView->getDisplayValue() . "\n");
                    
                    //Get the Offline of the each CustomView
                    echo("CustomView Offline: " . $customView->getOffline() . "\n");
                    
                    //Get the Default of each CustomView
                    echo("CustomView Default: " . $customView->getDefault() . "\n");
                    
                    //Get the SystemName of each CustomView
                    echo("CustomView SystemName: " . $customView->getSystemName() . "\n");
                    
                    //Get the SystemDefined of each CustomView
                    echo("CustomView SystemDefined: " . $customView->getSystemDefined() . "\n");
                    
                    //Get the Name of each CustomView
                    echo("CustomView Name: " . $customView->getName() . "\n");
                    
                    //Get the ID of each CustomView
                    echo("CustomView ID: " . $customView->getId() . "\n");
                    
                    //Get the Category of each CustomView
                    echo("CustomView Category: " . $customView->getCategory() . "\n");
                    
                    if($customView->getFavorite() != null)
                    {
                        //Get the Favorite of each CustomView
                        echo("CustomView Favorite: " . $customView->getFavorite() . "\n");
                    }
                }
                
                //Get the Object obtained Info instance
                $info = $responseWrapper->getInfo();
                
                //Check if info is not null
                if($info != null)
                {
                    if($info->getPerPage() != null)
                    {
                        //Get the PerPage of the Info
                        echo("CustomView Info PerPage: " . $info->getPerPage() . "\n");
                    }
                    
                    if($info->getDefault() != null)
                    {
                        //Get the Default of the Info
                        echo("CustomView Info Default: " . $info->getDefault() . "\n");
                    }
                    
                    if($info->getCount() != null)
                    {
                        //Get the Count of the Info
                        echo("CustomView Info Count: " . $info->getCount() . "\n");
                    }
                    
                    //Get the Translation instance of CustomView
                    $translation = $info->getTranslation();
                    
                    if($translation != null)
                    {
                        //Get the PublicViews of the Translation
                        echo("CustomView Info Translation PublicViews: " . $translation->getPublicViews() . "\n");
                        
                        //Get the OtherUsersViews of the Translation
                        echo("CustomView Info Translation OtherUsersViews: " . $translation->getOtherUsersViews() . "\n");
                        
                        //Get the SharedWithMe of the Translation
                        echo("CustomView Info Translation SharedWithMe: " . $translation->getSharedWithMe() . "\n");
                        
                        //Get the CreatedByMe of the Translation
                        echo("CustomView Info Translation CreatedByMe: " . $translation->getCreatedByMe() . "\n");
                    }
                    
                    if($info->getPage() != null)
                    {
                        //Get the Page of the Info
                        echo("CustomView Info Page: " . $info->getPage() . "\n");
                    }
                    
                    if($info->getMoreRecords() != null)
                    {
                        //Get the MoreRecords of the Info
                        echo("CustomView Info MoreRecords: " . $info->getMoreRecords() . "\n");
                    }
                }
            }
            //Check if the request returned an exception
            else if($responseHandler instanceof APIException)
            {
                //Get the received APIException instance
                $exception = $responseHandler;
                
                //Get the Status
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                
                //Get the Code
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                
                echo("Details: " );
                
                //Get the details map4
                foreach($exception->getDetails() as $key => $value)
                {
                    //Get each value in the map
                    echo($key . ": " .$value . "\n");
                }
                
                //Get the Message
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
        }
    }
}
 
Get a Custom View