Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.
package com.zoho.crm.sample.layouts
import java.util
import com.zoho.crm.api.fields.AssociationDetails
import com.zoho.crm.api.fields.AutoNumber
import com.zoho.crm.api.fields.Crypt
import com.zoho.crm.api.fields.Currency
import com.zoho.crm.api.fields.Field
import com.zoho.crm.api.fields.Formula
import com.zoho.crm.api.fields.LookupField
import com.zoho.crm.api.fields.Module
import com.zoho.crm.api.fields.MultiSelectLookup
import com.zoho.crm.api.fields.PickListValue
import com.zoho.crm.api.fields.ToolTip
import com.zoho.crm.api.fields.Unique
import com.zoho.crm.api.fields.ViewType
import com.zoho.crm.api.layouts.APIException
import com.zoho.crm.api.layouts.LayoutsOperations
import com.zoho.crm.api.layouts.Properties
import com.zoho.crm.api.layouts.ResponseHandler
import com.zoho.crm.api.layouts.ResponseWrapper
import com.zoho.crm.api.layouts.Section
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
object Layouts {
/**
* Get Layouts
* This method is used to get metadata about all the layouts of a module and print the response.
*
* @param moduleAPIName The API Name of the module to get layouts.
* @throws Exception
*/
@throws[Exception]
def getLayouts(moduleAPIName: String): Unit = { //example
//String moduleAPIName = "Leads"
//Get instance of LayoutsOperations Class that takes moduleAPIName as parameter
val layoutsOperations = new LayoutsOperations(Option(moduleAPIName))
//Call getLayouts method
val responseOption = layoutsOperations.getLayouts
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
println(if (response.getStatusCode == 204) "No Content"
else "Not Modified")
return
}
//Check if expected response is received
if (response.isExpected) { //Get object from response
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
//Get the list of obtained Layout instances
val layouts = responseWrapper.getLayouts
for (layout <- layouts) {
if (layout.getCreatedTime != null) { //Get the CreatedTime of each Layout
println("Layout CreatedTime: " + layout.getCreatedTime.toString)
}
//Check if ConvertMapping is not null
if (layout.getConvertMapping != null) { //Get the MultiModuleLookup map
layout.getConvertMapping.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
if (layout.getModifiedTime != null) { //Get the ModifiedTime of each Layout
println("Layout ModifiedTime: " + layout.getModifiedTime.toString)
}
//Get the Visible of each Layout
println("Layout Visible: " + layout.getVisible.toString)
//Get the createdFor User instance of each Layout
val createdForOption = layout.getCreatedFor
//Check if createdFor is not null
if (createdForOption.isDefined) { //Get the Name of the createdFor User
val createdFor=createdForOption.get
println("Layout CreatedFor User-Name: " + createdFor.getName)
//Get the ID of the createdFor User
println("Layout CreatedFor User-ID: " + createdFor.getId)
//Get the Email of the createdFor User
println("Layout CreatedFor User-Email: " + createdFor.getEmail)
}
//Get the Name of each Layout
println("Layout Name: " + layout.getName)
//Get the modifiedBy User instance of each Layout
val modifiedByOption = layout.getModifiedBy
//Check if modifiedBy is not null
if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
val modifiedBy=modifiedByOption.get
println("Layout ModifiedBy User-Name: " + modifiedBy.getName)
//Get the ID of the modifiedBy User
println("Layout ModifiedBy User-ID: " + modifiedBy.getId)
//Get the Email of the modifiedBy User
println("Layout ModifiedBy User-Email: " + modifiedBy.getEmail)
}
//Get the profiles of each Layout
val profiles = layout.getProfiles
//Check if profiles is not null
if (profiles != null) {
for (profile <- profiles) { //Get the Default of each Profile
println("Layout Profile Default: " + profile.getDefault.toString)
//Get the Name of each Profile
println("Layout Profile Name: " + profile.getName.toString)
//Get the ID of each Profile
println("Layout Profile ID: " + profile.getId.toString)
}
}
//Get the ID of each Layout
println("Layout ID: " + layout.getId)
//Get the createdBy User instance of each Layout
val createdByOption = layout.getCreatedBy
//Check if createdBy is not null
if (createdByOption.isDefined) { //Get the Name of the createdBy User
val createdBy=createdByOption.get
println("Layout CreatedBy User-Name: " + createdBy.getName)
//Get the ID of the createdBy User
println("Layout CreatedBy User-ID: " + createdBy.getId)
//Get the Email of the createdBy User
println("Layout CreatedBy User-Email: " + createdBy.getEmail)
}
//Get the sections of each Layout
val sections = layout.getSections
//Check if sections is not null
if (sections != null) {
for (section <- sections) { //Get the DisplayLabel of each Section
println("Layout Section DisplayLabel: " + section.getDisplayLabel)
//Get the SequenceNumber of each Section
println("Layout Section SequenceNumber: " + section.getSequenceNumber.toString)
//Get the Issubformsection of each Section
println("Layout Section Issubformsection: " + section.getIssubformsection.toString)
//Get the TabTraversal of each Section
println("Layout Section TabTraversal: " + section.getTabTraversal.toString)
//Get the APIName of each Section
println("Layout Section APIName: " + section.getAPIName)
//Get the ColumnCount of each Section
println("Layout Section ColumnCount: " + section.getColumnCount.toString)
//Get the Name of each Section
println("Layout Section Name: " + section.getName)
//Get the GeneratedType of each Section
println("Layout Section GeneratedType: " + section.getGeneratedType)
//Get the fields of each Section
val fields = section.getFields
if (fields != null) {
for (field <- fields) {
printField(field)
}
}
//Get the properties User instance of each Section
val propertiesOption = section.getProperties
//Check if properties is not null
if (propertiesOption.isDefined) { //Get the ReorderRows of each Properties
val properties = propertiesOption.get
println("Layout Section Properties ReorderRows: " + properties.getReorderRows.toString)
//Get the tooltip User instance of the Properties
val tooltipOption = properties.getTooltip
//Check if tooltip is not null
if (tooltipOption.isDefined) { //Get the Name of the ToolTip
val tooltip = tooltipOption.get
println("Layout Section Properties ToolTip Name: " + tooltip.getName.toString)
//Get the Value of the ToolTip
println("Layout Section Properties ToolTip Value: " + tooltip.getValue.toString)
}
//Get the MaximumRows of each Properties
println("Layout Section Properties MaximumRows: " + properties.getMaximumRows.toString)
}
}
}
//Get the Status of each Layout
println("Layout Status: " + layout.getStatus)
}
}
else { //Check if the request returned an exception
if (responseHandler.isInstanceOf[APIException]) { //Get the received APIException instance
val exception = responseHandler.asInstanceOf[APIException]
//Get the Status
println("Status: " + exception.getStatus.getValue)
//Get the Code
println("Code: " + exception.getCode.getValue)
println("Details: ")
//Get the details map
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
//Get the Message
println("Message: " + exception.getMessage.getValue)
}
}
}
else { //If response is not as expected
//Get model object from response
val responseObject = response.getModel
//Get the response object's class
val clas = responseObject.getClass
//Get all declared fields of the response class
val fields = clas.getDeclaredFields
for (field <- fields) { //Get each value
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
Get a Layout
package com.zoho.crm.sample.layouts
import java.util
import com.zoho.crm.api.fields.AssociationDetails
import com.zoho.crm.api.fields.AutoNumber
import com.zoho.crm.api.fields.Crypt
import com.zoho.crm.api.fields.Currency
import com.zoho.crm.api.fields.Field
import com.zoho.crm.api.fields.Formula
import com.zoho.crm.api.fields.LookupField
import com.zoho.crm.api.fields.Module
import com.zoho.crm.api.fields.MultiSelectLookup
import com.zoho.crm.api.fields.PickListValue
import com.zoho.crm.api.fields.ToolTip
import com.zoho.crm.api.fields.Unique
import com.zoho.crm.api.fields.ViewType
import com.zoho.crm.api.layouts.APIException
import com.zoho.crm.api.layouts.LayoutsOperations
import com.zoho.crm.api.layouts.Properties
import com.zoho.crm.api.layouts.ResponseHandler
import com.zoho.crm.api.layouts.ResponseWrapper
import com.zoho.crm.api.layouts.Section
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.users.User
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
object Layouts {
/**
* Get Layout
* This method is used to get metadata about a single layout of a module with layoutID and print the response.
*
* @param moduleAPIName The API Name of the layout's module
* @param layoutId The ID of the field to be obtained
* @throws Exception
*/
@throws[Exception]
def getLayout(moduleAPIName: String, layoutId: Long): Unit = { //Long layoutId = 34770691055l
val layoutsOperations = new LayoutsOperations(Option(moduleAPIName))
//Call getLayout method that takes layoutId as parameter
val responseOption = layoutsOperations.getLayout(layoutId)
if (responseOption.isDefined) {
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
println(if (response.getStatusCode == 204) "No Content"
else "Not Modified")
return
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
val layouts = responseWrapper.getLayouts
for (layout <- layouts) {
if (layout.getCreatedTime != null) println("Layout CreatedTime: " + layout.getCreatedTime.toString)
if (layout.getConvertMapping != null) {
layout.getConvertMapping.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
if (layout.getModifiedTime != null) println("Layout ModifiedTime: " + layout.getModifiedTime.toString)
println("Layout Visible: " + layout.getVisible.toString)
val createdByOption = layout.getCreatedBy
//Check if createdBy is not null
if (createdByOption.isDefined) { //Get the Name of the createdBy User
val createdBy=createdByOption.get
println("Layout CreatedBy User-Name: " + createdBy.getName)
//Get the ID of the createdBy User
println("Layout CreatedBy User-ID: " + createdBy.getId)
//Get the Email of the createdBy User
println("Layout CreatedBy User-Email: " + createdBy.getEmail)
}
println("Layout Name: " + layout.getName)
val modifiedByOption = layout.getModifiedBy
//Check if modifiedBy is not null
if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
val modifiedBy=modifiedByOption.get
println("Layout ModifiedBy User-Name: " + modifiedBy.getName)
//Get the ID of the modifiedBy User
println("Layout ModifiedBy User-ID: " + modifiedBy.getId)
//Get the Email of the modifiedBy User
println("Layout ModifiedBy User-Email: " + modifiedBy.getEmail)
}
val profiles = layout.getProfiles
if (profiles != null) {
for (profile <- profiles) {
println("Layout Profile Default: " + profile.getDefault.toString)
println("Layout Profile Name: " + profile.getName.toString)
println("Layout Profile ID: " + profile.getId.toString)
}
}
println("Layout ID: " + layout.getId)
val sections = layout.getSections
if (sections != null) {
for (section <- sections) {
println("Layout Section DisplayLabel: " + section.getDisplayLabel)
println("Layout Section SequenceNumber: " + section.getSequenceNumber.toString)
println("Layout Section Issubformsection: " + section.getIssubformsection.toString)
println("Layout Section TabTraversal: " + section.getTabTraversal.toString)
println("Layout Section APIName: " + section.getAPIName)
println("Layout Section ColumnCount: " + section.getColumnCount.toString)
println("Layout Section Name: " + section.getName)
println("Layout Section GeneratedType: " + section.getGeneratedType)
val fields = section.getFields
if (fields != null) {
for (field <- fields) {
printField(field)
}
}
val propertiesOption = section.getProperties
if (propertiesOption.isDefined) {
val properties=propertiesOption.get
println("Layout Section Properties ReorderRows: " + properties.getReorderRows.toString)
val tooltipOption = properties.getTooltip
if (tooltipOption.isDefined) {
val tooltip = tooltipOption.get
println("Layout Section Properties ToolTip Name: " + tooltip.getName.toString)
println("Layout Section Properties ToolTip Value: " + tooltip.getValue.toString)
}
println("Layout Section Properties MaximumRows: " + properties.getMaximumRows.toString)
}
}
}
println("Layout Status: " + layout.getStatus)
}
}
else if (responseHandler.isInstanceOf[APIException]) {
val exception = responseHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}