Create custledgeraccount from code

Hi

I’ve this code from create custledgeraccount:

select DimensionAttributeValueCombination index hint mainAccountIdx

where DimensionAttributeValueCombination.DisplayValue == MainAccount.MainAccountId

&& DimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::Account;

if(! DimensionAttributeValueCombination)

select DimensionAttributeValueCombination index hint mainAccountIdx

where DimensionAttributeValueCombination.MainAccount == MainAccount.RecId

&& DimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::DefaultAccount;

if(DimensionAttributeValueCombination.RecId)

{

CustLedgerAccounts.initValue();

custLedgerAccounts.postingProfile = custPostingProfile;

custLedgerAccounts.Num = _custTable.AccountNum;

custLedgerAccounts.SummaryLedgerDimension = DimensionAttributeValueCombination.RecId;

custLedgerAccounts.accountCode = TableGroupAll::Table;

custLedgerAccounts.insert();

}

However when I try to post a sale it gives me an error. If in the posting profile I manually select the ledger account, the problem is solved. How can I create the posting profile correctly?

Thanks

What error you are getting?

The system updates the isBlockedForManualEntry when this ledgerDimension is modified, look at the modifiedField method in that table

Cust profile posting created by code. Error registering invoices from sales order:

“The account number for the type of transaction the customer’s balance does not exist.”

If I go to the record created by code and go back to manually assign the ledger account, the error disappears