Scala SDK Samples - Assignment Rules Operations

Get Assignment Rules
              
              
package com.zoho.crm.sample.assignmentrules

import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.assignmentrules.AssignmentRulesOperations.GetAssignmentRuleParam
import com.zoho.crm.api.assignmentrules.AssignmentRulesOperations
import com.zoho.crm.api.assignmentrules.ResponseWrapper
import com.zoho.crm.api.assignmentrules.APIException  
@SuppressWarnings(Array("unused")) object AssignmentRules {
  /**
    * Get AssignmentRules
    * This method is used to get assignment rules
    */
  @throws[Exception]
  def getAssignmentRules(): Unit = { //example
    //Get instance of AssignmentRulesOperations Class
    val assignmentRuleOperations = new AssignmentRulesOperations()
    //Call getAssignmentRules method
    val responseOption = assignmentRuleOperations.getAssignmentRules()
    if (responseOption.isDefined) { //check response
      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
      }
      //Check if expected response is received
      if (response.isExpected) { //Get object from response
        val responseHandler = response.getObject
        responseHandler match {
          case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance
            //Get the list of obtained AssignmentRule instances
            val assignmentRules = responseWrapper.getAssignmentRules

            for (assignmentRule <- assignmentRules) {
              //Get the modified time of each AssignmentRule
              println("AssignmentRule Modified Time: " + assignmentRule.getModifiedTime().toString)

              //Get the created time of each AssignmentRule
              println("AssignmentRule Created Time: " + assignmentRule.getCreatedTime().toString)

              //Check if DefaultUser is not null
              if (assignmentRule.getDefaultAssignee().isDefined) {
                //Get the  DefaultUser of each AssignmentRule
                val defaultAssignee = assignmentRule.getDefaultAssignee().get
                //Get the Name of the Owner
                println("AssignmentRule DefaultUser User-ID: " + defaultAssignee.getId())

                //Get the ID of the Owner
                println("AssignmentRule DefaultUser User-Name: " + defaultAssignee.getName())
              }

              //Check if Module is not null
              if (assignmentRule.getModule().isDefined) {
                //Get the  Module of each AssignmentRule
                val module = assignmentRule.getModule().get
                //Get the Name of the Owner
                println("AssignmentRule Module ID: " + module.getId())

                //Get the ID of the Owner
                println("AssignmentRule Module API Name: " + module.getAPIName())
              }

              //Get the name of the AssignmentRule
              println("AssignmentRule  Name: " + assignmentRule.getName())

              //Check if modifiedBy is not null
              if (assignmentRule.getModifiedBy().isDefined) {
                //Get the modifiedBy User instance of each AssignmentRule
                val modifiedBy = assignmentRule.getModifiedBy().get

                //Get the Name of the modifiedBy User
                println("AssignmentRule Modified By User-Name: " + modifiedBy.getName())

                //Get the ID of the modifiedBy User
                println("AssignmentRule Modified By User-ID: " + modifiedBy.getId())

                //Get the Email of the modifiedBy User
                println("AssignmentRule Modified By User-Email: " + modifiedBy.getEmail())
              }

              //Check if createdBy is not null
              if (assignmentRule.getCreatedBy().isDefined) {
                //Get the createdBy User instance of each AssignmentRule
                val createdBy = assignmentRule.getCreatedBy().get
                //Get the name of the createdBy User
                println("AssignmentRule Created By User-Name: " + createdBy.getName())

                //Get the ID of the createdBy User
                println("AssignmentRule Created By User-ID: " + createdBy.getId())

                //Get the Email of the createdBy User
                println("AssignmentRule Created By User-Email: " + createdBy.getEmail())
              }

              //Get the ID of each AssignmentRule
              println("AssignmentRule ID: " + assignmentRule.getId())

              //Get the description of each AssignmentRule
              println("AssignmentRule description: " + assignmentRule.getDescription())
            }
          case _ => //Check if the request returned an exception
            responseHandler match {
              case exception: APIException => //Get the received APIException instance
                //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)
              case _ =>
            }
        }
      }
      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))
        }
      }
    }
  }
}
class AssignmentRules {}

 
Get Assignment Rule
              
              
package com.zoho.crm.sample.assignmentrules

import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.assignmentrules.AssignmentRulesOperations.GetAssignmentRuleParam
import com.zoho.crm.api.assignmentrules.AssignmentRulesOperations
import com.zoho.crm.api.assignmentrules.ResponseWrapper
import com.zoho.crm.api.assignmentrules.APIException
@SuppressWarnings(Array("unused")) object AssignmentRules {
/**
	* Get AssignmentRule
	 * This method is used to get a single assignment rule
	 * @param assignmentRuleID The id of the assignment rule
	*/
  @throws[Exception]
	def getAssignmentRule(assignmentRuleID: Long): Unit = {
		//Get instance of AssignmentRulesOperations Class 
		val assignmentRuleOperations = new AssignmentRulesOperations()
		
		val pm = new ParameterMap
		pm.add(new GetAssignmentRuleParam().module, "Leads")
		//Call getAssignmentRules method
		val responseOption = assignmentRuleOperations.getAssignmentRule(assignmentRuleID, Option(pm))
    
    if (responseOption.isDefined) { //check response  
		  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
      }
			//Check if expected response is received
      if (response.isExpected) { //Get object from response
        val responseHandler = response.getObject
        responseHandler match {
          case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance
            //Get the list of obtained AssignmentRule instances
            val assignmentRules = responseWrapper.getAssignmentRules

            for (assignmentRule <- assignmentRules) {
              //Get the modified time of each AssignmentRule
              println("AssignmentRule Modified Time: " + assignmentRule.getModifiedTime().toString)

              //Get the created time of each AssignmentRule
              println("AssignmentRule Created Time: " + assignmentRule.getCreatedTime().toString)

              //Check if DefaultUser is not null
              if (assignmentRule.getDefaultAssignee().isDefined) {
                //Get the  DefaultUser of each AssignmentRule
                val defaultAssignee = assignmentRule.getDefaultAssignee().get
                //Get the Name of the Owner
                println("AssignmentRule DefaultUser User-ID: " + defaultAssignee.getId())

                //Get the ID of the Owner
                println("AssignmentRule DefaultUser User-Name: " + defaultAssignee.getName())
              }

              //Check if Module is not null
              if (assignmentRule.getModule().isDefined) {
                //Get the  Module of each AssignmentRule
                val module = assignmentRule.getModule().get
                //Get the Name of the Owner
                println("AssignmentRule Module ID: " + module.getId())

                //Get the ID of the Owner
                println("AssignmentRule Module API Name: " + module.getAPIName())
              }

              //Get the name of the AssignmentRule
              println("AssignmentRule  Name: " + assignmentRule.getName())

              //Check if modifiedBy is not null
              if (assignmentRule.getModifiedBy().isDefined) {
                //Get the modifiedBy User instance of each AssignmentRule
                val modifiedBy = assignmentRule.getModifiedBy().get

                //Get the Name of the modifiedBy User
                println("AssignmentRule Modified By User-Name: " + modifiedBy.getName())

                //Get the ID of the modifiedBy User
                println("AssignmentRule Modified By User-ID: " + modifiedBy.getId())

                //Get the Email of the modifiedBy User
                println("AssignmentRule Modified By User-Email: " + modifiedBy.getEmail())
              }
              //Check if createdBy is not null
              if (assignmentRule.getCreatedBy().isDefined) {
                //Get the createdBy User instance of each AssignmentRule
                val createdBy = assignmentRule.getCreatedBy().get
                //Get the name of the createdBy User
                println("AssignmentRule Created By User-Name: " + createdBy.getName())

                //Get the ID of the createdBy User
                println("AssignmentRule Created By User-ID: " + createdBy.getId())

                //Get the Email of the createdBy User
                println("AssignmentRule Created By User-Email: " + createdBy.getEmail())
              }

              //Get the ID of each AssignmentRule
              println("AssignmentRule ID: " + assignmentRule.getId())

              //Get the description of each AssignmentRule
              println("AssignmentRule description: " + assignmentRule.getDescription())
            }
          case _ => //Check if the request returned an exception
            responseHandler match {
              case exception: APIException => //Get the received APIException instance
                //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)
              case _ =>
            }
        }
			}
      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))
        }
      }
    }
  }
}
class AssignmentRules {}