Hi guys, I got a requirement like I need to send all warehouses of the selected site while exporting using data entity.
Way 1: Computed column:
Step 1: Create a computed column in the Data entity.
Step 2: Create an extension class for Entity.
[ExtensionOf(dataentityviewstr(MyEntity))]
public final class MyEntity_Extension
{
}
Step 3: create a static method in that class.
Write the below logic.
public static str getWarehouse()
{
//The FOR XML PATH is creates a concatenated string from a result set.
TableName entityName = tableStr(MyEntity);
DataSourceName dataSourceName = dataEntityDataSourceStr(MyEntity, MyDataSource);
FieldName fieldName = fieldStr(MyTable, MYField);
SysDictTable myTestTable = new SysDictTable(tableNum(MyTestTable));
str Warehouse = myTestTable.fieldObject(fieldNum(MyTestTable,
Field1)).name(DbBackend::Sql);
str site = myTestTable.fieldObject(fieldNum(MyTestTable,
Field2)).name(DbBackend::Sql);
str testTablaName = myTestTable.name(DbBackend::Sql);
str entityField = SysComputedColumn::returnField(dataentityviewstr(MyEntity),
dataEntityDataSourceStr(MyEntity, MyDataSource),
fieldStr(MyTable, MYField));
// we can use like this
//entityField = SysComputedColumn::returnField(entityName, dataSourceName, fieldName);
return 'SELECT STUFF((SELECT ' + SysComputedColumn::returnLiteral(DirUtility::ListDelimiter) +
'+ RTRIM(EL.' + Warehouse +')'+
' FROM ' + testTablaName + ' EL' +
' WHERE EL.' + site +' = ' + entityField +
//' AND EL.' + Field2 + ' = ' +
//SysComputedColumn::returnField(entityName, dataSourceName, fieldName) +
' ORDER BY EL.' + Warehouse +
' FOR XML PATH(' + SysComputedColumn::returnLiteral('')
+ ')),1,1,'+ SysComputedColumn::returnLiteral('') + ')';
// This is retun 'Warehouse' based on site value.
}
// return SysComputedColumn::returnLiteral(''); // Retuns empty value.
Step 4: Add in fields properties.
Value : MyClass::getWarehouse
Standard Reference(In D365):
Entity : InventOperationalSitePostalAddressEntity;
Field : AddressLocationRoles
Class: LogisticsEntityLocationMapInterface
Method:concatenatedLocationRolesComputedFieldDefinition
Way 2: Non-Computed column(virtual Field):
Step 1: Create a field in the Data entity.
Step 2: Set is computed fields property to No.
Step 3: Create an extension class for Entity.
[ExtensionOf(dataentityviewstr(MyEntity))]
public final class MyEntity_Extension
{
}
Step 4: Write the postload method
public void postload()
{
str wareHouse;
next postload();
while select InventLocation
where InventLocation.inventSiteId == this.OperationalSiteId
{
wareHouse += InventSite.InventlocationId + DirUtility::ListDelimiter;
}
this.warehouse = wareHouse;
}
OutPut:
Similar output we get
Keep Daxing!!
No comments:
Post a Comment