Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Define the import process in the imports.xml metadata file.
  2. Create the template file defined in the imports.xml metadata file for the import process.
  3. Create a process class extending com.crm.process.CRMImportBean, responsible for parsing the file and processing its records and define this process in modules.xml metadata file.

1. Imports Metadata File

The import process must be defined in the imports.xml metadata file, as shown in the example below. The metadata file can be located under the <custom_project>/src/main/resources/metadatadirectory. Note that all of the information except importdescription must be defined in the file. The processes defined in this file will appear in the Imports page, under Foundation > Utilities and you can view their process run logs, download their template file and submit them through this page.

Code Block
languagejava
themeEclipse
titleimports.xml
collapsetrue
<importsconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/imports.xsd">
	<imports>
		...
		
		<import>
			<importname>Custom Import</importname>
			<importdescription>Custom Import in CRM.COM.</importdescription>
			<importprocess>CUSTOM_IMPORT</importprocess>
			<importmodule>CUSTOM</importmodule>
			<importtemplatefilepath>imports/customTemplateFile.csv</importtemplatefilepath>
		</import>

		...
	</imports>
</importsconfig>

2. Template File

The template file will be used as an example for the file used by the import process and can be downloaded from the import data entry page. The file must be placed under the directory defined in the imports.xml metadata file, with the importtemplatefilepath tag.

3. Import Process class

A process class must be created for the import process, extending com.crm.process.CRMImportBean. Below, you can see the implementation of an example import process class. It is recommended to use the LogTextFile method to log the import process results for easier debugging of the process.

...

Next, you must define this process class and the method that will be called for the import in the modules.xml metadata file, which can be found under the <custom_project>/src/main/resources/metadata/ directory. Note that the <importprocess> and <importmodule> defined in the imports.xml file will be used in the modules.xml metadata file to correcty define the process class. The <importprocess> will be used as the process id and the <importmodule> as the module id, as shown below.

...

To create an export process, you need to create:

  1. Define the export process in the exports.xml metadata file.
  2. Create a process class extending  extending com.crm.process.CRMExportBean, responsible for parsing creating the file and processing its records.
  3. user interface class extending com.crm.process.processrun.CRMUIProcessRunDefinitionBean, responsible for handling the process run definition's page.
  4. summary page to display the export process definitions.
  5. data entry page to give the user the ability to create, view, edit, delete, save and run an export process definition.

In the following example, we will implement a mechanism to export vouchers. In order to do so, we create CRMExportVoucherBean.java and implement exportVoucher method, which retrieves the vouchers to be exported based on the given lot and writes them to a file of a given type (EXCEL, CSV, XML).

...

languagejava
themeEclipse
titleexportVoucher method
collapsetrue

...

  1. export file.

1. Exports Metadata File

The export process must be defined in the exports.xml metadata file, as shown in the example below. The metadata file can be located under the <custom_project>/src/main/resources/metadatadirectory. Note that all of the information except exportdescription must be defined in the file. The processes defined in this file will appear in the Exports page, under Foundation > Utilities and you can view their process run logs and submit them through this page.

Code Block
languagejava
themeEclipse
titleexports.xml
collapsetrue
<exportsconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/exports.xsd">
	<exports>
		...

		<export>
			<exportname>Custom Export</exportname>
			<exportdescription>Custom Export in CRM.COM.</exportdescription>
			<exportprocess>CUSTOM_EXPORT</exportprocess>
			<exportmodule>CUSTOM</exportmodule>
		</export>

		...
	</exports>
</exportsconfig>

2. Export Process class

A process class must be created for the export process, extending com.crm.process.CRMExportBean. Below, you can see the implementation of an example export process class. It is recommended to use the LogTextFile method to log the export process results for easier debugging of the process.

Code Block
languagejava
themeEclipse
titleexportVoucher method
collapsetrue
public class EXAMPLEExportBean extends CRMExportBean {   

...
 	public void export(String processRunLogID) throws Exception {
        
 processRun.setStatus(ProcessRunLogStatus.IN_PROGRESS);
        processRun.setStartDate(getCurrentDate());
 		CallList.LogTextFile(getCRMSession(), "Example Export start processing (" + processRunLogID + ")", "exportExample","");

		CRMDOProcessRunLog processRun = (CRMDOProcessRunLog)processRunLogBean.load(processRunLogID);
    
        processRun.setStatus(ProcessRunLogStatus.IN_PROGRESS);
    	processRun.setStartDate(getCurrentDate());
    	processRunLogBean.save(processRun);
        
        Boolean processComplete = new Boolean(false);
    
        try
        {
    			exportInExcelFormat(processRun);
           CRMDOLot lot = exportVoucherDefinition.getLot(); 
           VoucherFileFormat fileFormatprocessComplete = new exportVoucherDefinition.getVoucherFileFormatBoolean(true);
            
        }
   if (lot != null && fileFormatcatch !=(Exception nulle)
        {
			CallList.LogTextFile(getCRMSession(), "Error on {processing export (" + processRunLogID + ")" + ExceptionUtil.getStackTrace(e), "exportExample","");

            processRun.setStatus(ProcessRunLogStatus.FAILED);
           if (fileFormatprocessRunLogBean.equalssave(VoucherFileFormat.EXCELprocessRun));
        }
       { 
        if (processComplete)   
      exportVoucherInExcelFormat(exportVoucherDefinition, lot, processRun);{
            processRun.setStatus(ProcessRunLogStatus.COMPLETED);
   }                 else if (fileFormat.equals(VoucherFileFormat.CSV))processRun.setEndDate(getCurrentDate());
            processRunLogBean.save(processRun);
   {     }

		CallList.LogTextFile(getCRMSession(), "Example Export end processing (" + processRunLogID       exportVoucherInCSVFormat(exportVoucherDefinition, lot, processRun);
           + ")", "exportExample","");
    }
                else if (fileFormat.equals(VoucherFileFormat.XML))
                {
                    exportVoucherInXMLFormat(exportVoucherDefinition, lot, processRun);
                }
                processComplete = new Boolean(true);
            }
        }
        catch (Exception e)
        {
            processRun.setStatus(ProcessRunLogStatus.FAILED);
            processRunLogBean.save(processRun);
        }
        
        if (processComplete)   
        {
            processRun.setStatus(ProcessRunLogStatus.COMPLETED);
            processRun.setEndDate(getCurrentDate());
            processRunLogBean.save(processRun);
        }
    }

	public void exportVoucherInExcelFormat(ExportVoucherDefinition exportVoucherDefinition, CRMDOLot lot, CRMDOProcessRunLog processRun) throws Exception{
                
        ResultSetUtil vouchers = processVoucherBean.getVouchersToBeExported(lot.getId());
        if (vouchers!=null && vouchers.getRowCount()>0)
        {                
            ArrayList<String[]> excelRecords = new ArrayList<String[]>();
            while(vouchers.next())
            {
                String voucherID = vouchers.getString("VOUCHERID");
                CRMDOVoucher voucher = (CRMDOVoucher) voucherBean.load(voucherID);    
                
                try
                {                    
                    excelRecords.add(constructRecord(voucher));
                }
                catch (Exception e)
                {
                    Entity voucherEntity = MetadataUtil.getEntityByClass(CRMDOVoucher.class.getName(), getCRMSession().getRealPath(), getOrganisationID());
                    processLogBean.createEntityLogRecord(
                            processRun.getId(), 
                            voucher.getId(),
                            voucherEntity.getId(),
                            ProcessRunLogEntityStatus.FAILED.toString(),
                            e.getClass().getSimpleName(), 
                            ExceptionUtil.getStackTrace(e));
                }
            }
            
            storeEXCELRows(excelRecords, processRun, getFileHeaders());
        }
        else
        {
            throw new VoucherNotFoundToBeExportedException(getCRMSession());
        }
    }

..	
...
}


Next, you must define this process class and the method that will be called for the export in the modules.xml metadata file, which can be found under the <custom_project>/src/main/resources/metadata/ directory. Note that the <exportprocess> and <exportmodule> defined in the exports.xml file will be used in the modules.xml metadata file to correcty define the process class. The <exportprocess> will be used as the process id and the <exportmodule> as the module id. The process can be defined in the same way as the import process, shown above.