Hello everyone,
I recently started working on a feature to create ledger journal entries through a new form that handles loan requests from employees.
The process starts when an authorized person submits a loan request for a specific employee. This creates a new record in a custom table I made to store these requests. Then, someone else approves the request and clicks "Send for Payment." At this point, I need to follow a structure defined by the finance team, which includes a "Main Account" and "Personnel Number."
I wrote code that creates a row in ledgerJournalTable, followed by another row in ledgerJournalTrans, which contains the journal details.
However, I face an issue: sometimes I can get the LedgerDimension for the employee, and other times I can't. Here’s the code I use:
public static DimensionDynamicAccount generateLedgerDimension(DimensionAttributeRecId _recId, MainAccountNum _mainAccountId, HcmPersonnelNumberId _personnelNumber)
{
RecId dimAttId_MainAccount;
LedgerRecId ledgerRecId;
MainAccount mainAccount;
RefRecId recordvalue;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionSetSegmentName DimensionSet;
DimensionStorage dimStorage;
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List valueContracts = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
mainAccount = MainAccount::findByMainAccountId(_mainAccountId);
recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId, Ledger::current());
DimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue);
dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionAttribute::find(_recId).Name);
if (dimensionAttribute)
{
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, _personnelNumber, true, true);
if (dimensionAttributeValue)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName(dimensionAttribute.Name);
ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
valueContracts.addEnd(ValueContract);
}
}
LedgerAccountContract.parmMainAccount(_mainAccountId);
LedgerAccountContract.parmValues(valueContracts);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
ledgerRecId = dimensionAttributeValueCombination.RecId;
return ledgerRecId;
}
After meeting with the finance team, they confirmed that once they finish creating the Dimension structure, the system automatically generates Dimensions for all employees without exceptions.
I searched the DimensionAttributeValue table and found that employees for whom I couldn’t create a ledger journal didn’t have records there. However, when I manually created a ledger journal from the "Vendor Payment Journal" screen, the missing data was added automatically.
One solution I found is setting a parameter in DimensionAttributeValue::findByDimensionAttributeAndValue to true, which creates a new entry in the DimensionAttributeValue table.
This approach works but makes me uneasy because I don’t know if directly creating entries through code could cause issues or conflict with system logic.
What are the potential risks of this solution? Would this approach be safe?
Thank you all.