Skip to main content

Scala SDK Samples - Layouts Operations

Get Layouts
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))
        }
      }
    }
  }
}