Record Cloning
Introduction
Record Cloning is used to replicate or duplicate a certain record. All the data within a record is replicated into a new record with a new record number. Using this feature, you can create similar records multiple times with minimal data change in certain fields. This way, the rest of the data remains intact and only the fields that need to be updated are changed in the new record.
You can use this feature in the following two scenarios:
- In a general scenario, a record in an object is cloned with the rest of the data. The object is independent of other objects, and there is no relationship established with the other objects.
- In a specific scenario, a record in an object is cloned with the rest of the data including the related information and the sub-forms. The object is dependent on other objects, and there is a relationship established with the other objects.
Record Cloning is done using a piece of Java code. This Java code provides the functionality using AgileApps macros.
Creating the functionality
Write the code on the Class page of the Developer Resources sub-module. You can locate the the same by going to Configuration > Customization > Developer Resources > Classes.
Executing the functionality
Use the MACROS feature of AgileApps that allows you to create a dropdown feature in the record view section.
Configuring the macros
- Go to Configuration > Customization > Objects > {object} > Macros and click New Macro.
- Under the Basic Information section, provide the name and description of the macro.
- Under the Visibility Criteria section, select Unconditionally (Always) for a condition.
- Under the Actions to Perform section, select Invoke Method in the first drop-down. Select the class and the respective method listed in the second drop-down.
You can use the following sample code for record cloning:
package com.platform.softwareag_agileapps.test; import com.platform.api.*; import com.platform.api.Logger; import java.util.*; import com.platform.beans.*; import com.platform.api.Result; import com.platform.api.Parameters; public class recordClone { //This section is used for Initializing Variables public void cloneRecord(Parameters p) throws Exception { String recordId = p.get("id"); // Gets Record_ID (id) for the Object String record_ObjectId = p.get("object_id"); // Gets object_id for Object Logger.debug(recordId, "recordClone"); Logger.trace(record_ObjectId,"recordClone"); try { //Get the object name based on the object id. CustomObjectMetaDataBean mdb = Functions.getObjectMetaData(record_ObjectId); Logger.info("The objject id at getting object name"+record_ObjectId, "recordClone"); String objectName=mdb.getObjectName(); Logger.trace("The object name is " +objectName, "recordClone"); //Adding the current record, as Parameters object "p" contains all the record data. Behaves similar to this object. Result addRecordResult = Functions.addRecord(objectName,p); int recordCode = addRecordResult.getCode(); if(recordCode<0) { String msg = "Record cannot be cloned"; Logger.info(msg + ":\n" + addRecordResult.getMessage(), objectName); // Log details Functions.throwError(msg + "."); // Error message } Logger.trace("the keys are "+p, "recordClone"); } catch (Exception e) { String msg = e.getMessage() + "\n methodName(): "+e.getClass().getName(); Functions.throwError(msg); } } }