1. Extending document distribution as customization with custom entities
1.1. Extend enum EXADocuEntityType with the custom entities
Start by adding the entities you want to add as a type in an extension of the 'EXADocuEntityType' base enum. As an example, an entity called 'NewEntity' was added to the enum, make sure your naming makes sense for your entity (see the other standard examples).
1.2. Extend table EXADocuDistributionTable
Here we extend the 'EXADocuDistributionTable' table. This Is so we can map the D365 FO tables to the entity type we added in the previous section.
[ExtensionOf(tableStr(EXADocuDistributionTable))]
internal final class EXADocuDistributionTable_Table_ADU_Extension
{
public static EXADocuEntityType convertCommonToEntityType(Common _common)
{
EXADocuEntityType entityType;
;
entityType = next convertCommonToEntityType(_common);
if(entityType == EXADocuEntityType::None)
{
switch(_common.TableId)
{
case tableNum(NewEntityTable)
entityType = EXADocuEntityType::NewEntity;
break;
}
}
}
public static RefTableId convertEntityTypeToTableId(EXADocuEntityType _docuEntityType)
{
RefTableId refTableId;
;
refTableId = next convertEntityTypeToTableId(_docuEntityType);
if(!RefTableId)
{
switch(_docuEntityType)
{
case EXADocuEntityType::NewEntity
refTableId = tableNum(NewEntityTable);
break;
}
}
}
}
1.3. Implementation of the distribution
In this next step, we will add the actual distribution of the documents to the pieces of code where we want them to get distributed. Usually it will be a piece of code that you need to call when you insert new records, like with the creation of for example a purchase order line.
As an example, we'll have a look at how to copy documents from an item to your newly made purchase order line. You need to call the class 'EXADocuDistributionManager' with 2 parameters; your 'From' record (in this example the table 'InventTable'), and your 'To' record (in this example the table 'Purchline')
[ExtensionOf(classStr(PurchLineType))]
public final class PurchLineType_Class_EXADocu_Extension
{
public void inserted()
{
;
next inserted();
this.exaDistributeDocuments();
}
/// <summary>
/// Distribute documents from released product entity to purchase order line entity
/// </summary>
public void exaDistributeDocuments()
{
Common commonFrom;
;
If(isConfigurationKeyEnabled(configurationKeyNum(EXARaptorDocuMgmt)) == true && EXADocuDistributionManager::canDistributeOnPurchLine(this.parmPurchLine()) == true)
{
commonFrom = this.parmPurchline().inventTable();
if(commonFrom.RecId != 0 && this.parmPurchLine().RecId != 0)
{
EXADocuDistributionManager::distributeFromEntityToEntity(commonFrom, this.parmPurchLine());
}
}
}
}