Scala SDK Samples - Modules Operations
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Get Module
* This method is used to get metadata about single module with it's API Name and print the response.
*
* @param moduleAPIName The API Name of the module to obtain metadata
* @throws Exception
*/
@throws[Exception]
def getModule(moduleAPIName: String): Unit = { //example
//String moduleAPIName = "Leads"
val moduleOperations = new ModulesOperations
//Call getModule method that takes moduleAPIName as parameter
val responseOption = moduleOperations.getModule(moduleAPIName)
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
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
val modules = responseWrapper.getModules
for (module <- modules) {
println("Module Name: " + module.getName)
println("Module GlobalSearchSupported: " + module.getGlobalSearchSupported.toString)
if (module.getKanbanView != null) { //Get the KanbanView of each Module
println("Module KanbanView: " + module.getKanbanView.toString)
}
println("Module Deletable: " + module.getDeletable.toString)
println("Module Description: " + module.getDescription)
println("Module Creatable: " + module.getCreatable.toString)
if (module.getFilterStatus != null) { //Get the FilterStatus of each Module
println("Module FilterStatus: " + module.getFilterStatus.toString)
}
println("Module InventoryTemplateSupported: " + module.getInventoryTemplateSupported.toString)
if (module.getModifiedTime != null) println("Module ModifiedTime: " + module.getModifiedTime)
println("Module PluralLabel: " + module.getPluralLabel)
println("Module PresenceSubMenu: " + module.getPresenceSubMenu.toString)
println("Module TriggersSupported: " + module.getTriggersSupported.toString)
println("Module Id: " + module.getId.toString)
//Get the RelatedListProperties instance of each Module
val relatedListPropertiesOption = module.getRelatedListProperties
//Check if relatedListProperties is not null
if (relatedListPropertiesOption.isDefined) { //Get the SortBy of each RelatedListProperties
val relatedListProperties=relatedListPropertiesOption.get
println("Module RelatedListProperties SortBy: " + relatedListProperties.getSortBy)
//Get List of fields APIName
val fields = relatedListProperties.getFields
//Check if fields is not null
if (fields != null) {
for (fieldName <- fields) { //Get the Field Name
println("Module RelatedListProperties Fields: " + fieldName)
}
}
//Get the Name of RelatedListProperties
println("Module RelatedListProperties SortOrder: " + relatedListProperties.getSortOrder)
}
//Get List of properties field APIName
val properties = module.getproperties()
//Check if properties is not null
if (properties != null) {
for (fieldName <- properties) {
println("Module Properties Fields: " + fieldName)
}
}
//Get the PerPage of each Module
println("Module PerPage: " + module.getPerPage.toString)
println("Module Visibility: " + module.getVisibility.toString)
println("Module Convertable: " + module.getConvertable.toString)
println("Module Editable: " + module.getEditable.toString)
println("Module EmailtemplateSupport: " + module.getEmailtemplateSupport.toString)
val profiles = module.getProfiles
if (profiles != null) {
for (profile <- profiles) {
println("Module Profile Name: " + profile.getName)
println("Module Profile Id: " + profile.getId.toString)
}
}
println("Module FilterSupported: " + module.getFilterSupported.toString)
//Get the DisplayField of each Module
println("Module DisplayField: " + module.getDisplayField)
//Get List of SearchLayoutFields APIName
val searchLayoutFields = module.getSearchLayoutFields
//Check if searchLayoutFields is not null
if (searchLayoutFields != null) {
for (fieldName <- searchLayoutFields) {
println("Module SearchLayoutFields Fields: " + fieldName)
}
}
if (module.getKanbanViewSupported != null) { //Get the KanbanViewSupported of each Module
println("Module KanbanViewSupported: " + module.getKanbanViewSupported.toString)
}
println("Module ShowAsTab: " + module.getShowAsTab.toString)
println("Module WebLink: " + module.getWebLink)
println("Module SequenceNumber: " + module.getSequenceNumber.toString)
println("Module SingularLabel: " + module.getSingularLabel)
println("Module Viewable: " + module.getViewable.toString)
println("Module APISupported: " + module.getAPISupported.toString)
println("Module APIName: " + module.getAPIName)
println("Module QuickCreate: " + module.getQuickCreate.toString)
val modifiedByOption = module.getModifiedBy
if (modifiedByOption.isDefined) {
val modifiedBy=modifiedByOption.get
println("Module Modified By User-Name: " + modifiedBy.getName)
println("Module Modified By User-ID: " + modifiedBy.getId)
}
println("Module GeneratedType: " + module.getGeneratedType.getValue)
println("Module FeedsRequired: " + module.getFeedsRequired.toString)
println("Module ScoringSupported: " + module.getScoringSupported.toString)
println("Module WebformSupported: " + module.getWebformSupported.toString)
val arguments = module.getArguments
if (arguments != null) {
for (argument <- arguments) {
println("Module Argument Name: " + argument.getName)
println("Module Argument Value: " + argument.getValue)
}
}
println("Module ModuleName: " + module.getModuleName)
println("Module BusinessCardFieldLimit: " + module.getBusinessCardFieldLimit.toString)
//Get the CustomView instance of each Module
val customViewOption = module.getCustomView
//Check if customView is not null
if (customViewOption.isDefined) printCustomView(customViewOption.get)
val parentModuleOption = module.getParentModule
if (parentModuleOption.isDefined ) {
val parentModule = parentModuleOption.get
println("Module Parent Module Name: " + parentModule.getAPIName)
println("Module Parent Module Id: " + parentModule.getId.toString)
}
}
}
else if (responseHandler.isInstanceOf[APIException]) {
val exception = responseHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
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))
}
}
}
}
}
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Update Module By APIName
* This method is used to update module details using module APIName and print the response.
*
* @param moduleAPIName The API Name of the module to update
* @throws Exception
*/
@throws[Exception]
def updateModuleByAPIName(moduleAPIName: String): Unit = {
val moduleOperations = new ModulesOperations
val modules = new ArrayBuffer[Module]
val profiles = new ArrayBuffer[Profile]
//Get instance of Profile Class
val profile = new Profile
//To set the Profile Id
profile.setId(Option(347706126014l))
// profile.setDelete(true)
profiles.addOne(profile)
val module = new Module
module.setProfiles(profiles)
modules.addOne(module)
val request = new BodyWrapper
request.setModules(modules)
//Call updateModuleByAPIName method that takes BodyWrapper instance and moduleAPIName as parameter
val responseOption = moduleOperations.updateModuleByAPIName(moduleAPIName,request )
if (responseOption.isDefined) { //check response
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
//Get the list of obtained ActionResponse instances
val actionResponses = actionWrapper.getModules
for (actionResponse <- actionResponses) { //Check if the request is successful
if (actionResponse.isInstanceOf[SuccessResponse]) { //Get the received SuccessResponse instance
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.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 if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
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))
}
}
}
}
}
package com.zoho.crm.sample.modules
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.customviews.Criteria
import com.zoho.crm.api.customviews.CustomView
import com.zoho.crm.api.customviews.SharedDetails
import com.zoho.crm.api.modules.APIException
import com.zoho.crm.api.modules.ActionHandler
import com.zoho.crm.api.modules.ActionResponse
import com.zoho.crm.api.modules.ActionWrapper
import com.zoho.crm.api.modules.Argument
import com.zoho.crm.api.modules.BodyWrapper
import com.zoho.crm.api.modules.Module
import com.zoho.crm.api.modules.ModulesOperations
import com.zoho.crm.api.modules.ModulesOperations.GetModulesHeader
import com.zoho.crm.api.modules.RelatedListProperties
import com.zoho.crm.api.modules.ResponseHandler
import com.zoho.crm.api.modules.ResponseWrapper
import com.zoho.crm.api.modules.SuccessResponse
import com.zoho.crm.api.profiles.Profile
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Modules {
/**
* Update Module By Id
* This method is used to update module details using module Id and print the response.
*
* @param moduleId - The Id of the module to obtain metadata
* @throws Exception
*/
@throws[Exception]
def updateModuleById(moduleId: Long): Unit = { //Long moduleId = 34770613905003L
val moduleOperations = new ModulesOperations
val modules = new ArrayBuffer[Module]
val profiles = new ArrayBuffer[Profile]
val profile = new Profile
profile.setId(Option(347706106014l))
profiles.addOne(profile)
val module = new Module
module.setProfiles(profiles)
module.setAPIName(Option("apiName1"))
modules.addOne(module)
val request = new BodyWrapper
request.setModules(modules)
//Call updateModuleById method that takes BodyWrapper instance and moduleId as parameter
val responseOption = moduleOperations.updateModuleById(moduleId,request )
if (responseOption.isDefined) { //check response
val response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getModules
for (actionResponse <- actionResponses) {
if (actionResponse.isInstanceOf[SuccessResponse]) {
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.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 if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
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))
}
}
}
}
}