RECORD CLONING AS A FEATURE USING AGILEAPPS JAVA API's
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 changed 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 generally or specifically.
- When used generally, 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.
- When used specifically, 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 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 in the CLASS section of the developer resources tab.
- You can find the CLASS section under:
Configuration → Customization → Developer Resources → Classes
Executing the functionality:
Use the MACROS feature of AgileApps which allows you to create a dropdown feature in the record view section.
Configuring the macros :
Configuration -> Customization -> Objects -> {object} -> Macros -> New Macro 1. Name the macros 2. Provide a description, if required, 3. Select unconditionally for a condition 4. Under actions -> Select Invoke Method and Invoke the class and respective methodYou can use the below general 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);
}
}
}