Daily journal and invoice journal got freeze if i create from code

Hi Experts,

I am creating daily journal through code , journal is creating and posting successfully. But before posting if want to edit something system not allowing me to edit anything. But if i create same journal manually i am able to edit.

Below code i am using for auto journal.

MCRLedgerJournal journalTable;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTransupd;
Counter recordsInserted;
PurchParameters purchParameters;
AmountMST amountcredit,amountdebit;
Chargecodelines ChargeCodes,chargeCodesUpd;
AgreementHeader agreementHeader;
AgreementLine agreementLine;
PurchAgreementHeader purchAgreementHeader;
SalesAgreementHeader salesAgreementHeader;
MarkupTable markupTable;
LedgerDimensionAccount ledgerAccount,offsetAccount;
NumberSeq numberSeq;
Voucher voucher;
ttsbegin;
select _eTG_ChargeCodes
where _eTG_ChargeCodes.ETGLineestimationno == eTG_Estimation ;
select purchParameters;
journalTable = new MCRLedgerJournal_Daily(LedgerJournalType::Daily,purchParameters.ETGEstimationLedgerJournalName);
//Instatiate the General Journal Table
ledgerJournalTable = journalTable.createLedgerJournalTable(purchParameters.ETGEstimationLedgerJournalName);

journalTable.parmLedgerJournalTable(ledgerJournalTable);
voucher = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();
journalTable.parmMCRCCGeneralLedgerId(voucher);
journalTable.parmLedgerAccountType(LedgerJournalACType::Ledger);
journalTable.parmLedgerOffsetAccountType(LedgerJournalACType::Ledger);
//journalTable.parmExchRate(_eTG_ChargeCodes.ExchangeRate);
journalTable.parmCurrencyCode(_eTG_ChargeCodes.CurrencyCode);
journalTable.parmLineNum();

select markupTable where markupTable.MarkupCode == _eTG_ChargeCodes.MarkupCode &&
markupTable.ETG_CustomerLedgerDimension != 0 &&
markupTable.ETG_VendLedgerDimension !=0;
select RecId from purchAgreementHeader
where purchAgreementHeader.PurchNumberSequence == _eTG_ChargeCodes.PurchNumberSequence
join agreementLine
where agreementLine.Agreement == purchAgreementHeader.RecId;
if(purchAgreementHeader)
{
ledgerAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_CustomerLedgerDimension,
agreementLine.DefaultDimension);
offsetAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_VendLedgerDimension,
agreementLine.DefaultDimension);
}
select RecId from salesAgreementHeader
where salesAgreementHeader.SalesNumberSequence == _eTG_ChargeCodes.PurchNumberSequence
join agreementLine
where agreementLine.Agreement == salesAgreementHeader.RecId;
if(salesAgreementHeader)
{
ledgerAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_CustomerLedgerDimension,
agreementLine.DefaultDimension);
offsetAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_VendLedgerDimension,
agreementLine.DefaultDimension);
}
journalTable.parmLedgerAccount(ledgerAccount);
journalTable.parmledgerOffsetAccount(offsetAccount);
journalTable.parmTransDate(today());
journalTable.parmTransTxt(purchParameters.ETGEstimationLedgerJournalName);
amountdebit = _eTG_ChargeCodes.AmountMST;
journalTable.createLedgerJournalTrans(abs(0),abs(amountdebit),LedgerJournalACType::Ledger);

recordsInserted++;

ttscommit;

can anyone suggest me what i missed.

First of all, please describe the problem. What happens when “system not allowing you to edit anything”? Do you get an error? Is the journal marked as locked by system? Or what?

Then please mention your version of AX. Please allways attach a version tag (e.g. AX 2012 or D365FO) when creating a new thread.

Most of your code doesn’t seem to be necessary to demonstrate your problem, but anyway, let me improve it by removing unused variables, add indentation and paste it through Insert > Insert Code. Please do such things by yourself next time.

MCRLedgerJournal journalTable;
LedgerJournalTable ledgerJournalTable;
Counter recordsInserted;
PurchParameters purchParameters = PurchParameters::find();
AmountMST amountdebit;
AgreementLine agreementLine;
PurchAgreementHeader purchAgreementHeader;
SalesAgreementHeader salesAgreementHeader;
MarkupTable markupTable;
LedgerDimensionAccount ledgerAccount, offsetAccount;
Voucher voucher;

ttsbegin;

select _eTG_ChargeCodes
	where _eTG_ChargeCodes.ETGLineestimationNo == eTG_Estimation;

journalTable = new MCRLedgerJournal_Daily(LedgerJournalType::Daily, purchParameters.ETGEstimationLedgerJournalName);
//Instatiate the General Journal Table
ledgerJournalTable = journalTable.createLedgerJournalTable(purchParameters.ETGEstimationLedgerJournalName);

journalTable.parmLedgerJournalTable(ledgerJournalTable);
voucher = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();
journalTable.parmMCRCCGeneralLedgerId(voucher);
journalTable.parmLedgerAccountType(LedgerJournalACType::Ledger);
journalTable.parmLedgerOffsetAccountType(LedgerJournalACType::Ledger);
journalTable.parmCurrencyCode(_eTG_ChargeCodes.CurrencyCode);
journalTable.parmLineNum();

select markupTable
	where markupTable.MarkupCode == _eTG_ChargeCodes.MarkupCode
	   && markupTable.ETG_CustomerLedgerDimension != 0
	   && markupTable.ETG_VendLedgerDimension !=0;
		
select RecId from purchAgreementHeader
	where purchAgreementHeader.PurchNumberSequence == _eTG_ChargeCodes.PurchNumberSequence
	join agreementLine
		where agreementLine.Agreement == purchAgreementHeader.RecId;
	
if (purchAgreementHeader)
{
	ledgerAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_CustomerLedgerDimension, agreementLine.DefaultDimension);
	offsetAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_VendLedgerDimension, agreementLine.DefaultDimension);
}

select RecId from salesAgreementHeader
	where salesAgreementHeader.SalesNumberSequence == _eTG_ChargeCodes.PurchNumberSequence
	join agreementLine
		where agreementLine.Agreement == salesAgreementHeader.RecId;
	
if (salesAgreementHeader)
{
	ledgerAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_CustomerLedgerDimension, agreementLine.DefaultDimension);
	offsetAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(markupTable.ETG_VendLedgerDimension, agreementLine.DefaultDimension);
}

journalTable.parmLedgerAccount(ledgerAccount);
journalTable.parmledgerOffsetAccount(offsetAccount);
journalTable.parmTransDate(today());
journalTable.parmTransTxt(purchParameters.ETGEstimationLedgerJournalName);
amountdebit = _eTG_ChargeCodes.AmountMST;
journalTable.createLedgerJournalTrans(abs(0), abs(amountdebit), LedgerJournalACType::Ledger);

recordsInserted++;

ttscommit;