Scala SDK Samples - Inventory Templates Operations

Get Inventory Templates
              
              
package com.zoho.crm.sample.inventorytemplates

import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.inventorytemplates.{InventoryTemplatesOperations, ResponseWrapper}
import com.zoho.crm.api.inventorytemplates.InventoryTemplatesOperations.GetInventoryTemplatesParam
import com.zoho.crm.api.inventorytemplates.APIException

object InventoryTemplates {
   /*
	 * Get InventoryTemplates 
	 * This method is used to get Inventory Templates
	 * @throws Exception
	 */
	def getInventoryTemplates(): Unit = {	
		// Get instance of InventoryTemplatesOperations Class
		val moduleAPIName = "Quotes"
		val sortby = "modified_time"
		val sortOrder = "desc"
		val category = "created_by_me"
		val inventoryTemplatesOperations = new InventoryTemplatesOperations(Option(sortby), Option(sortOrder), Option(category))
		
		val paramInstance = new ParameterMap()
		
		paramInstance.add(new GetInventoryTemplatesParam().module, moduleAPIName)

		// Call getInventoryTemplates method
		val responseOption = inventoryTemplatesOperations.getInventoryTemplates(Option(paramInstance))
		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

				responseHandler match {
					case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance

						// Get the list of obtained InventoryTemplate instances
						val inventoryTemplates = responseWrapper.getInventoryTemplates

						for (inventoryTemplate <- inventoryTemplates) {
							// Get the CreatedTime of each InventoryTemplate
							println("InventoryTemplate CreatedTime: " + inventoryTemplate.getCreatedTime())

							// Get the Subject of each InventoryTemplate
							println("InventoryTemplate Subject: " + inventoryTemplate.getSubject())

							// Get the Module of each InventoryTemplate
							val moduleOption = inventoryTemplate.getModule()
							if (moduleOption.isDefined) {
								val module = moduleOption.get
								// Get the ID of Module
								println("InventoryTemplate Module ID: " + module.getId())

								// Get the apiName of Module
								println("InventoryTemplate Module apiName: " + module.getAPIName())
							}

							// Get the Type of each InventoryTemplate
							println("InventoryTemplate Type: " + inventoryTemplate.getType())

							//Get the  Created by
							val createdByOption = inventoryTemplate.getCreatedBy()
							if (createdByOption.isDefined) {
								val createdBy = createdByOption.get
								println("InventoryTemplate Created By Name : " + createdBy.getName())
								println("InventoryTemplate Created By id : " + createdBy.getId())
							}
							// Get the ModifiedTime of each InventoryTemplate
							println("InventoryTemplate ModifiedTime: " + inventoryTemplate.getModifiedTime())

							//Get the  Created by
							val folderOption = inventoryTemplate.getFolder()

							if (folderOption.isDefined) {
								val folder = folderOption.get
								println("InventoryTemplate Folder  id : " + folder.getId())
								println("InventoryTemplate Folder  Name : " + folder.getName())
							}
							// Get the Last Usage time of each InventoryTemplate
							println("InventoryTemplate Last Usage Time: " + inventoryTemplate.getLastUsageTime())

							// Get the Associated of each InventoryTemplate
							println("InventoryTemplate Associated: " + inventoryTemplate.getAssociated())

							// Get the Name of each InventoryTemplate
							println("InventoryTemplate Name: " + inventoryTemplate.getName())

							//Get the  Modified by
							val modifiedByOption = inventoryTemplate.getModifiedBy()

							if (modifiedByOption.isDefined) {
								val modifiedBy = modifiedByOption.get
								println("InventoryTemplate Modified By Name : " + modifiedBy.getName())
								println("InventoryTemplate Modified By id : " + modifiedBy.getId())
							}

							// Get the ID of each InventoryTemplate
							println("InventoryTemplate ID: " + inventoryTemplate.getId())

							// Get the Editor mode of each InventoryTemplate
							println("InventoryTemplate : " + inventoryTemplate.getEditorMode())

							println("InventoryTemplate Content: " + inventoryTemplate.getContent())

							// Get the Description of each InventoryTemplate
							println("InventoryTemplate Description: " + inventoryTemplate.getDescription())

							// Get the EditorMode of each InventoryTemplate
							println("InventoryTemplate EditorMode: " + inventoryTemplate.getEditorMode())

							// Get the Favourite of each InventoryTemplate
							println("InventoryTemplate Favourite: " + inventoryTemplate.getFavorite())

							// Get the Favourite of each InventoryTemplate
							println("InventoryTemplate Subject: " + inventoryTemplate.getSubject())

						}

						//Get the Object obtained Info instance
						val infoOption = responseWrapper.getInfo()

						//Check if info is not null
						if (infoOption.isDefined) {
							val info = infoOption.get
							if (info.getPerPage() != null) {
								//Get the PerPage of the Info
								println("Record Info PerPage: " + info.getPerPage().toString)
							}

							if (info.getCount() != null) {
								//Get the Count of the Info
								println("Record Info Count: " + info.getCount().toString)
							}

							if (info.getPage() != null) {
								//Get the Page of the Info
								println("Record Info Page: " + info.getPage().toString)
							}

							if (info.getMoreRecords() != null) {
								//Get the MoreRecords of the Info
								println("Record Info MoreRecords: " + info.getMoreRecords().toString)
							}
						}
					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: ")

								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 InventoryTemplates {}
 
Get Inventory Template
              
              
package com.zoho.crm.sample.inventorytemplates

import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.inventorytemplates.{InventoryTemplatesOperations, ResponseWrapper}
import com.zoho.crm.api.inventorytemplates.InventoryTemplatesOperations.GetInventoryTemplatesParam
import com.zoho.crm.api.inventorytemplates.APIException

object InventoryTemplates {
  def getInventoryTemplate(InventoryTemplateID: Long): Unit = { //example,
		// Get instance of InventoryTemplatesOperations Class
		val sortby ="modified_time"
		val sortOrder = "desc"
		val category = "created_by_me"
		val inventoryTemplatesOperations = new InventoryTemplatesOperations()

		// Call getInventoryTemplates method
		val responseOption = inventoryTemplatesOperations.getInventoryTemplateById(InventoryTemplateID)
		if (responseOption.isDefined) {
			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

				responseHandler match {
					case responseWrapper: ResponseWrapper => //Get the received ResponseWrapper instance

						// Get the list of obtained InventoryTemplate instances
						val inventoryTemplates = responseWrapper.getInventoryTemplates()

						for (inventoryTemplate <- inventoryTemplates) {
							// Get the CreatedTime of each InventoryTemplate
							println("InventoryTemplate CreatedTime: " + inventoryTemplate.getCreatedTime())

							// Get the Subject of each InventoryTemplate
							println("InventoryTemplate Subject: " + inventoryTemplate.getSubject())

							// Get the Module of each InventoryTemplate
							val moduleOption = inventoryTemplate.getModule()
							if (moduleOption.isDefined) {
								val module = moduleOption.get
								// Get the ID of Module
								println("InventoryTemplate Module ID: " + module.getId())

								// Get the apiName of Module
								println("InventoryTemplate Module apiName: " + module.getAPIName())
							}

							// Get the Type of each InventoryTemplate
							println("InventoryTemplate Type: " + inventoryTemplate.getType())

							//Get the  Created by
							val createdByOption = inventoryTemplate.getCreatedBy()

							if (createdByOption.isDefined) {
								val createdBy = createdByOption.get
								println("InventoryTemplate Created By Name : " + createdBy.getName())
								println("InventoryTemplate Created By id : " + createdBy.getId())
							}
							// Get the ModifiedTime of each InventoryTemplate
							println("InventoryTemplate ModifiedTime: " + inventoryTemplate.getModifiedTime())

							//Get the  Created by
							val folderOption = inventoryTemplate.getFolder()

							if (folderOption.isDefined) {
								val folder = folderOption.get
								println("InventoryTemplate Folder  id : " + folder.getId())
								println("InventoryTemplate Folder  Name : " + folder.getName())
							}
							// Get the Last Usage time of each InventoryTemplate
							println("InventoryTemplate Last Usage Time: " + inventoryTemplate.getLastUsageTime())

							// Get the Associated of each InventoryTemplate
							println("InventoryTemplate Associated: " + inventoryTemplate.getAssociated())

							// Get the Name of each InventoryTemplate
							println("InventoryTemplate Name: " + inventoryTemplate.getName())

							//Get the  Modified by
							val modifiedByOption = inventoryTemplate.getModifiedBy()

							if (modifiedByOption.isDefined) {
								val modifiedBy = modifiedByOption.get
								println("InventoryTemplate Modified By Name : " + modifiedBy.getName())
								println("InventoryTemplate Modified By id : " + modifiedBy.getId())
							}

							// Get the ID of each InventoryTemplate
							println("InventoryTemplate ID: " + inventoryTemplate.getId())

							// Get the Editor mode of each InventoryTemplate
							println("InventoryTemplate : " + inventoryTemplate.getEditorMode())

							println("InventoryTemplate Content: " + inventoryTemplate.getContent())

							// Get the Description of each InventoryTemplate
							println("InventoryTemplate Description: " + inventoryTemplate.getDescription())

							// Get the EditorMode of each InventoryTemplate
							println("InventoryTemplate EditorMode: " + inventoryTemplate.getEditorMode())

							// Get the Favourite of each InventoryTemplate
							println("InventoryTemplate Favourite: " + inventoryTemplate.getFavorite())

							// Get the Favourite of each InventoryTemplate
							println("InventoryTemplate Subject: " + inventoryTemplate.getSubject())
						}
					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: ")

								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 InventoryTemplates {}