Scala SDK Samples - Layouts Operations

Get Layouts
              
              
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 {
                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 {
              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 
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 = 3477061000000091055l
    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 {
                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 {
            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