Skip to main content

Scala SDK Samples - Variable Groups Operations

Get All Variable Groups
Get a Variable Group by its Group ID
              
              
package com.zoho.crm.sample.variablegroups

import java.util
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.{APIException, ResponseHandler, ResponseWrapper, VariableGroup, VariableGroupsOperations}
import scala.collection.mutable.ArrayBuffer

object Variablegroup {
  /**
   *  Get Variable Group By Id 
   * This method is used to get the details of any variable group with group id and print the response.
   *
   * @param variableGroupId - The ID of the VariableGroup to be obtained
   * @throws Exception
   */
  @throws[Exception]
  def getVariableGroupById(variableGroupId: Long): Unit = { //example
    //Long variableGroupId = 3477061000003089001l
    val variableGroupsOperations = new VariableGroupsOperations
    //Call getVariableGroupById method that takes variableGroupId as parameter
    val responseOption = variableGroupsOperations.getVariableGroupById(variableGroupId)
    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
      }
      if (response.isExpected) {
        val responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) {
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          val variableGroups = responseWrapper.getVariableGroups
          variableGroups.foreach(variableGroup => { //Get the DisplayLabel of each VariableGroup
            println("VariableGroup DisplayLabel: " + variableGroup.getDisplayLabel)
            println("VariableGroup APIName: " + variableGroup.getAPIName)
            println("VariableGroup Name: " + variableGroup.getName)
            println("VariableGroup Description: " + variableGroup.getDescription)
            println("VariableGroup ID: " + variableGroup.getId)

          })
        }
        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))
        }
      }
    }
  }
}
Get a Variable Group by its API Name
              
              
package com.zoho.crm.sample.variablegroups

import java.util
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.{APIException, ResponseHandler, ResponseWrapper, VariableGroup, VariableGroupsOperations}
import scala.collection.mutable.ArrayBuffer

object Variablegroup {
  /**
   *  Get Variable Group By APIName 
   * This method is used to get the details of any variable group with group name and print the response.
   *
   * @param variableGroupName - The API Name of the VariableGroup to be obtained
   * @throws Exception
   */
  @throws[Exception]
  def getVariableGroupByAPIName(variableGroupName: String): Unit = { //String variableGroupName = "General"
    val variableGroupsOperations = new VariableGroupsOperations
    //Call getVariableGroupByAPIName method that takes variableGroupName as parameter
    val responseOption = variableGroupsOperations.getVariableGroupByAPIName(variableGroupName)
    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
      }
      if (response.isExpected) {
        val responseHandler = response.getObject
        if (responseHandler.isInstanceOf[ResponseWrapper]) {
          val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
          val variableGroups = responseWrapper.getVariableGroups
          variableGroups.foreach(variableGroup => { //Get the DisplayLabel of each VariableGroup
            println("VariableGroup DisplayLabel: " + variableGroup.getDisplayLabel)
            println("VariableGroup APIName: " + variableGroup.getAPIName)
            println("VariableGroup Name: " + variableGroup.getName)
            println("VariableGroup Description: " + variableGroup.getDescription)
            println("VariableGroup ID: " + variableGroup.getId)

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