Sample Groovy Scripts To maintain Custom Objects in Oracle Fusion Cloud

Vishal Palakurthi
2 min readSep 20, 2023

--

In Orale Fusion ERP Cloud, we create custom objects to store some extra information or capture additional information related to any seeded objects without the need for any extension. We create groovy scripts to access object records and sync them with the main flow.

So, this writing will help in maintaining those custom objects and some handy groovy scripts ready-made to be used.

some keywords

  1. println → To print the information on the Run time diagnostics screen
  2. while → For looping the records from the view
  3. def → to declare the handler (a variable)
  4. try , catch , → To handle the exception
  5. ${e} → to access the exception message
  6. // → To comment single line
  7. /* */ → To comment block

Script 1: To Delete records from custom objects

println(‘Entered into DeleteObjectRecords’); → This will write to the run time diagnostics

def exdata = newView(“Categories_c”); //use API name to access custom object
exdata.executeQuery(); // Execute to get the view rows into cache
println(exdata.getEstimatedRowCount());// print the count
exdata.reset(); // reset to first record
while (exdata.hasNext()){ // Looping
println(‘Removing the record:’);
def row = exdata.next()
row.remove(); // Remove record.
}

Script 2: To get the child object records from the parent object using the view criteria

Below code is from parent object

println(‘WhentTheFieldValueSelected For Employee After Set Attribute’);
println(‘EmployeeName_c’+EmployeeName_c);
println(‘HRPosition_c’+HRPosition_c); // This is the current view field name
println(‘HRPosition_c’+HRPosition_Id_c); // This is the foreign key of the record that has the child record.
if (length(HRPosition_c) > 1)
{
def OrgObj = newView(‘ALLPositions_c’)
println(OrgObj.getEstimatedRowCount());
def ResViewCriteria = OrgObj.createViewCriteria()
def ResViewCriteriaRow = ResViewCriteria.createRow()
def ResViewCriteriaItem = ResViewCriteriaRow.ensureCriteriaItem(‘Id’)
ResViewCriteriaItem.setOperator(‘=’)
ResViewCriteriaItem.setValue(HRPosition_Id_c)
ResViewCriteria.insertRow(ResViewCriteriaRow)
OrgObj.appendViewCriteria(ResViewCriteria)
OrgObj.executeQuery()
if(OrgObj.hasNext()) {
def orgrow = OrgObj.next()
setAttribute(‘EmployeeName_c’,orgrow.getAttribute(‘EmployeeName_c’));
println(orgrow.getAttribute(‘EmployeeName_c’));
}
}

Script 3: Calling the BIP report and insert it into the custom object. (It is preferred to use the import management for the uploads of high volume)

PreRequisite: Here we are using the web service to call the BIP report and results are inserted into the database. This web service first needs to be registered under the service section.

In the below RunReportWebservice is the web service registered. For authentication, we can use the SAML authentication

def reportRequest =
[
byPassCache :true,
flattenXML :false,
reportAbsolutePath :’/Custom/Reports/Extension/Signature/PositionsReport.xdo’,
sizeOfDataChunkDownload :-1,
]
def appParams = ‘’;
def result=adf.webServices.RunReportWebservice.runReport(reportRequest, appParams);
def decoderesult=decodeBase64(result.reportBytes.toString());
println(‘Report REsult in Base64’+ decoderesult);
println(‘Results’+decoderesult);
String PositionName = ‘POSITION_NAME’;
String [] arrresult;
arrresult = decoderesult.split(‘\n’);
def exdata = newView(“Positions_c”);
exdata.executeQuery();
exdata.reset();
def count = 0;
String PositionName_val = ‘’;
for (data in arrresult)
{
println(‘InsideTheLoop’)
count = count+1;
if (contains(data,PositionName))
{
PositionName_val = substringBefore(substringAfter(data,’>’),’<’);
println(‘positionValue:’+ PositionName_val);
def amper = ‘&amp;’;
println(‘positionValueBefore:’+ substringBefore(PositionName_val,amper));
println(‘positionValueAfter:’+ substringAfter(PositionName_val,amper));
println(‘positionValueAfter:’+ PositionName_val.replaceAll(amper,’&’));
};

if (PositionName_val != ‘’)
{
def amper = ‘&amp;’;
def DataRow1 = exdata.createRow();
DataRow1.setAttribute(“RecordName”,PositionName_val.replaceAll(amper,’&’));
DataRow1.setAttribute(“PositionName_c”,PositionName_val.replaceAll(amper,’&’));
exdata.insertRow(DataRow1);
PositionName_val = ‘’;
}
}

--

--