To loop through all the fields available in a table we need to use the following code.It will give us the required properties specified for a field. Now im fetching the table fields labels dynamically.
Anyhow Batch job will have its own contract and controllers
/// <summary>
/// Helper class to export labels to data lake
/// </summary>
class ExportLabelsToDataLakeBatch extends SysOperationServiceBase
{
QueryRun queryRun;
RecordInsertList list;
DictField _dictField;
DataLakeLabelsTable dataLakeLabelsTable;
str fieldLabel,edtLabel,enumLabel;
FormDataSource formDataSource;
/// <summary>
/// to call the process method
/// </summary>
/// <param name = "_dataContract">datacontract</param>
public void run(ExportLabelsContract _dataContract)
{
Set recordSet;
SetEnumerator se;
Common record;
DataFeedsTableCatalog dataFeedsTableCatalog;
// Process records
if (conLen(_dataContract.parmRecordCon()) > 0)
{
recordSet = Set::create(_dataContract.parmRecordCon());
se = recordSet.getEnumerator();
while (se.moveNext())
{
record = se.current();
switch (record.TableId)
{
case tableNum(DataFeedsTableCatalog):
dataFeedsTableCatalog = record;
this.processRecord(dataFeedsTableCatalog.TableIdValue);
break;
default:
info(strFmt("%1", record.RecId));
}
}
}
}
/// <summary>
/// Method used to prrocess the labels in every language
/// </summary>
/// <param name = "_tableId">Tablenumber</param>
public void ProcessRecord(TableId _tableId)
{
LanguageTable languageTable;
list = new RecordInsertList(tableNum(DataLakeLabelsTable));
while select languageTable
index hint key
{
this.getTablefieldsLabels(_tableId, languageTable.LanguageId);
}
list.insertDatabase();
}
/// <summary>
/// Used to retrieve the label value of each field
/// </summary>
/// <param name = "_tableId">Table num</param>
/// <param name = "_languageId">Language</param>
public void getTablefieldsLabels(TableId _tableId, LanguageId _languageId)
{
DictTable dt=new SysDictTable(_tableId);
FieldId _fieldId= dt.fieldNext(0);
while(_fieldId)
{
try
{
ttsbegin;
_dictField =dt.fieldObject(_fieldId);
if(T07_DataLakeLabelsTable::find(_dictField.tableid(), _dictField.id(),_languageId))
{
_fieldId= dt.fieldNext(_fieldId);
ttscommit;
continue;
}
if(_dictField.label())
{
SysDictField sysdictfield = new SysDictField(_dictField.tableid(), _dictField.id());
fieldLabel = SysLabel::labelId2String(sysdictfield.labelLabel(),_languageId);
if (fieldLabel)
{
this.intilizeDatalakeTable(fieldLabel, _languageId);
}
}
else
{
if(_dictField.type() == Types::UserType)
{
SysDictType sysDictType = new SysDictType(_dictField.typeId());
edtLabel = SysLabel::labelId2String(sysDictType.labelLabel(),_languageId);
if(edtLabel)
{
this.intilizeDatalakeTable(edtLabel, _languageId);
}
}
else if(_dictField.type() == Types::Enum)
{
SysDictEnum sysDictEnum = new SysDictEnum(_dictField.enumId());
enumLabel = SysLabel::labelId2String(sysDictEnum.labelLabel(),_languageId);
if (enumLabel)
{
this.intilizeDatalakeTable(enumLabel, _languageId);
}
}
}
_fieldId= dt.fieldNext(_fieldId);
ttscommit;
}
catch(Exception::Error)
{
ttsabort;
continue;
}
}
}
/// <summary>
/// Intilize data in DataLake custom table
/// </summary>
/// <param name = "_labelvale">label value</param>
/// <param name = "_languageId">Language</param>
public void intilizeDatalakeTable(str _labelvale, LanguageId _languageId)
{
dataLakeLabelsTable.FieldNumber = _dictField.id();
dataLakeLabelsTable.FieldName = fieldId2Name(_dictField.tableid(), _dictField.id());
dataLakeLabelsTable.TableName = tableId2Name(_dictField.tableid());
dataLakeLabelsTable.Language = _languageId;
dataLakeLabelsTable.LabelValue = _labelvale;
dataLakeLabelsTable.Tablenumber = _dictField.tableid();
if(_dictField.type() == Types::UserType)
{
dataLakeLabelsTable.BaseType = extendedTypeId2name( _dictField.typeId());
}
else if(_dictField.type() == Types::Enum)
{
dataLakeLabelsTable.BaseType = enumId2Name(_dictField.enumId());
}
list.add(dataLakeLabelsTable);
}
}