...
The import parameters should be defined in the metadata file to enable the user to give some default values to the respective parameters of the template file. If import parameters are defined, the user will be able to set their values through the import definition data entry page. The import parameters are mapped to the template file's parameters through the importparametername, which must be the same as the name of the header of the respective parameter in the template file. So, based on the example below, the template file must have columns with headers custom_parameter1 and custom_parameter2. When defining the import parameters, it is mandatory to define all the information for them. The importparameterkey is the label that will appear for the parameter in the data entry page and the importparametertype is the type of the parameter and it can be one of the following: java.lang.String, text, java.lang.Integer, java.math.BigDecimal, java.util.Date, password, java.lang.Boolean and enum. If enum is defined as the type, then an additional tag must be defined, the importparameterclassname, which indicates the class of the import parameter.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<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> <importparameters> <importparameter> <importparametername>custom_parameter1</importparametername> <importparameterkey>key_custom_parameter1</importparameterkey> <importparametertype>java.math.BigDecimal</importparametertype> </importparameter> <importparameter> <importparametername>custom_parameter2</importparametername> <importparameterkey>key_custom_parameter2</importparameterkey> <importparametertype>enum</importparametertype> <importparametertype>java.lang.String</importparametertype><importparameterclassname>com.crm.dataobject.contactinfo.AddressTypes</importparameterclassname> </importparameter> ... </importparameters> </import> ... </imports> </importsconfig> |
...
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.
If import parameters where defined in the imports.xml metadata file, then their values can be retrieved and used from the process run log's process run definition, using the loadCustomImportActionInputsFromXML method of the ProcessRunDefinitionXMLUtilBean class.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public class EXAMPLEImportBean extends CRMImportBean { ... public void import(String processRunLogID) throws Exception{ CallList.LogTextFile(getCRMSession(), "Example Import start processing (" + processRunLogID + ")", "importExample",""); CRMDOProcessRunLog processRun = (CRMDOProcessRunLog)processRunLogBean.load(processRunLogID); ArrayList<CRMDO> attachments = attachmentBean.load(processRun); processRun.setStatus(ProcessRunLogStatus.IN_PROGRESS); processRun.setStartDate(getCurrentDate()); processRunLogBean.save(processRun); Boolean processComplete = new Boolean(false); ProcessRunLogStatus processRunLogStatus = null; try { for (int i=0;i<attachents.size();i++) { CRMDOAttachment attachment = (CRMDOAttachment)attachments.get(i); String[] tokens = StringUtil.split(attachment.getFileName(),"."); String extension = tokens[tokens.length-1]; SupportedImportFileExtensions[] supportedImportFileExtensions = SupportedImportFileExtensions.values(); for (int j=0; j<supportedImportFileExtensions.length; j++) { SupportedImportFileExtensions supportedImportFileExtension = supportedImportFileExtensions[j]; if (supportedImportFileExtension.isSupported(extension)) { if (supportedImportFileExtension.equals(SupportedImportFileExtensions.EXCEL)) { importEXCEL(attachment,processRun,extension); } else if (supportedImportFileExtension.equals(SupportedImportFileExtensions.CSV)) { importCSV(attachment,processRun); } else if (supportedImportFileExtension.equals(SupportedImportFileExtensions.XML)) { importXML(attachment,processRun); } } } } processComplete = new Boolean(true); } catch (Exception e) { CallList.LogTextFile(getCRMSession(), "Error on processing import (" + processRunLogID + ")" + ExceptionUtil.getStackTrace(e), "importExample",""); saveEntityLogRecord(processRun,"", "",ProcessRunLogEntityStatus.FAILED,e.getClass().getSimpleName(),ExceptionUtil.getStackTrace(e)); processRun.setStatus(ProcessRunLogStatus.FAILED); processRunLogBean.save(processRun); } if (processComplete) { processRun.setStatus(processRunLogStatus); processRun.setEndDate(getCurrentDate()); processRunLogBean.save(processRun); } CallList.LogTextFile(getCRMSession(), "Example Import end processing (" + processRunLogID + ")", "importExample",""); } ... } |
...