Android SDK Samples - Related Lists Operations

Get Related Lists
          
          
//$module object is of ZCRMModule

//call getRelatedLists() using $module object
$module.getRelatedLists(object :DataCallback<BulkAPIResponse,List<ZCRMModuleRelation>>
    {
       override fun completed(response: BulkAPIResponse,moduleRelations: List<ZCRMModuleRelation>) {
           println("${response.responseJSON}")
       }
    
       override fun failed(exception: ZCRMException) {
           println("Throws Exception: $exception")
       }
    
    })
 
Get Related Lists from the Server
          
          
//$module object is of ZCRMModule

//call getRelatedListsFromServer() using $module object
$module.getRelatedListsFromServer(object :DataCallback<BulkAPIResponse,List<ZCRMModuleRelation>>
    {
       override fun completed(response: BulkAPIResponse,moduleRelations: List<ZCRMModuleRelation>) {
           println("${response.responseJSON}")
       }
    
       override fun failed(exception: ZCRMException) {
           println("Throws Exception: $exception")
       }
    
    })
 
Get a Related List
          
          
//$module object is of ZCRMModule

//call getRelatedList() using $module object by passing relatedlistId as a parameter

//relatedlistId - Id of the Related list to be returned

$module.getRelatedList(371xxx797, object:DataCallback<APIResponse,ZCRMModuleRelation>
    {
        override fun completed(response: APIResponse, moduleRelation: ZCRMModuleRelation) {
            println("${response.responseJSON}")
        }
    
        override fun failed(exception: ZCRMException) {
            println("Throws Exception: $exception")
        }
    
    })
    
 
Get a Related List from the Server
          
          
//$module object is of ZCRMModule

//call getRelatedListFromServer() using $module object by passing relatedlistId as a parameter

//relatedlistId - Id of the Related list to be returned

$module.getRelatedListFromServer(371xxx797, object:DataCallback<APIResponse,ZCRMModuleRelation>
    {
        override fun completed(response: APIResponse, moduleRelation: ZCRMModuleRelation) {
            println("${response.responseJSON}")
        }
    
        override fun failed(exception: ZCRMException) {
            println("Throws Exception: $exception")
        }
    
    })
 
Get Related Records' Data
          
          
val parentRecord = ZCRMSDKUtil.getModuleDelegate("Contacts").getRecordDelegate(371xxx06) //id - ID of the record

val recordParams = ZCRMQuery.Companion.GetRecordParams()
recordParams.includePrivateFields

//$moduleRelation object is of ZCRMModuleRelation

//call getRelatedRecords() using the $moduleRelation object by passing the parentRecord and recordParams as parameters 

//parentRecord - Record object of the ZCRMRecordDelegate. 

//recordParams - Record parameters are given as an object.

$moduleRelation.getRelatedRecords(parentRecord,recordParams,object:DataCallback<BulkAPIResponse,List<ZCRMRecord>>
{
   override fun completed(response: BulkAPIResponse, zcrmentity: List<ZCRMRecord>) {
       println("${response.responseJSON}")
   }

   override fun failed(exception: ZCRMException) {
       println("Throws Exception: $exception")
   }

})
 
Update Related Records
          
          
val junctionRecords = arrayListOf<ZCRMJunctionRecord>()

val parentRecord = ZCRMSDKUtil.getModuleDelegate("Contacts").getRecordDelegate(371xxx006) //id - ID of the record

//$moduleRelation object is of ZCRMModuleRelation

//define the related records with their values

//call getJunctionRecordInstance() using $moduleRelation object by passing relatedRecordId as parameter

//relatedRecordId - Id of the related record

val relatedRec1 = $moduleRelation.getJunctionRecordInstance(371xxx005)
        relatedRec1.setFieldValue("list_price","600")

val relatedRec2 = $moduleRelation.getJunctionRecordInstance(371xxx016)
        relatedRec2.setFieldValue("quantity_in_stock","1200")

//add the related records to the junctionRecords list
    junctionRecords.add(relatedRec1)
    junctionRecords.add(relatedRec2)

//adding the junction records to the parent record as relations by calling addRelations()
//pass the list of junction records as a parameter to the addRelations()
parentRecord.addRelations(junctionRecords,object:ResponseCallback<BulkAPIResponse>{
    override fun completed(response: BulkAPIResponse) {
        println("${response.responseJSON}")
    }

    override fun failed(exception: ZCRMException) {
        println("Throws Exception: $exception")
    }

})
 
          
          
val junctionRecords = arrayListOf<ZCRMJunctionRecord>()

val parentRecord = ZCRMSDKUtil.getModuleDelegate("Contacts").getRecordDelegate(371xxx006)//id - ID of the record

//$moduleRelation is the object of ZCRMModuleRelation

//call getJunctionRecordInstance() using $moduleRelation object by passing relatedRecordId as parameter

//relatedRecordId - Id of the related record

val relatedRec1 = $moduleRelation.getJunctionRecordInstance(371xxx005)

val relatedRec2 = $moduleRelation.getJunctionRecordInstance(371xxx016)

    junctionRecords.add(relatedRec1)
    junctionRecords.add(relatedRec2)


//call deleteRelations() by passing the junctionRecords list as a parameter

parentRecord.deleteRelations(junctionRecords,object:ResponseCallback<BulkAPIResponse>{
    override fun completed(response: BulkAPIResponse) {
        println("${response.responseJSON}")
    }

    override fun failed(exception: ZCRMException) {
        println("Throws Exception: $exception")
    }

})