web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Vendor Invoice Journal...
Finance forum

Vendor Invoice Journal (Creation Via X++)-Is non Editable in Form on front end

(0) ShareShare
ReportReport
Posted on by

Hello Everyone

I am trying to create vendor invoice journal through code as shown in the below.The journal is created as shown the second screenshot but it is opening in non editable mode on the front end .Kindly provide your valuable suggestions.

4403.Capture_5F00_1.PNG

Code:-

class OA
{
	public static void main (Args _args)
	{
		OATPChargesPost OATPChargesPost;
		FormDataSource tpCharges_DS;
		OATPCharges tpCharges, tpChargesIns, tpChargesRow;
		Dialog dialog;
		LedgerJournalCheckPost jourCheckPost;
		LedgerJournalTable jourTable;
		LedgerJournalTrans jourTrans;
		container offsetDim;
		DimensionAttributeValueConsolidation davc, davcOffset;
		MarkupTable markupTable;
		MCRLedgerJournal journalTable;
		LedgerJournalTable ledgerJournalTable;
		Counter recordsInserted = 0;
		MarkupTrans markupTrans;

		OATPChargesPost = OATPChargesPost::construct();

		if(_args.record().TableId == tableNum(OATPCharges))
		{
			tpCharges = _args.record();
			tpCharges_DS = tpCharges.dataSource();

			dialog = new Dialog("@OA:OA1");
			dialog.addText("@OA:OA2");

			if (dialog.run())
			{
				if (tpCharges_DS.anyMarked())
				{
					tpChargesRow = tpCharges_DS.getFirst( 1, false);

					ttsBegin;

					journalTable = new MCRLedgerJournal_VendInvoiceRegister(LedgerJournalType::VendInvoiceRegister, "APInvoice");
					ledgerJournalTable = journalTable.createLedgerJournalTable("APInvoice");

					journalTable.parmLedgerJournalTable(ledgerJournalTable);
					journalTable.parmMCRCCGeneralLedgerId();
					journalTable.parmLedgerAccountType(LedgerJournalACType::Vend);
					journalTable.parmAccountNum(tpChargesRow.OATPVendAccount);
					journalTable.parmLedgerOffsetAccountType(LedgerJournalACType::Ledger);
					journalTable.parmLineNum(recordsInserted + 1);
					journalTable.parmApprover(HcmWorker::findByPersonnelNumber("000001").RecId);
					journalTable.parmExchRate(100);
					journalTable.parmCurrencyCode('USD');
					journalTable.parmTransTxt("Test");

					markuptable = MarkupTable::find(tpChargesRow.ModuleType, tpChargesRow.MarkupCode);

					journalTable.parmledgerOffsetAccount(markupTable.VendorLedgerDimension);
					journalTable.parmTransDate(DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()));
					journalTable.parmPostingProfile("Gen");
					journalTable.parmPaymTermId("Net30");
					journalTable.parmPaymMode("Check");
					journalTable.parmDueDate(mkDate(12,12,2018));

					while (tpChargesRow)
					{
						jourTrans = journalTable.createLedgerJournalTrans(tpChargesRow.Value,0,LedgerJournalACType::Vend);

						if(jourTrans)
						{
							ttsbegin;
							jourTrans.selectForUpdate(true);
							jourTrans.OAMarkupTrans = tpChargesRow.MarkupTrans;
							jourTrans.update();
							ttscommit;
							recordsInserted++;
						}

						tpChargesRow = tpCharges_DS.getNext();
					}
					ttsCommit;
				}
			}
		}
	}

	public static OATPChargesPost construct()
	{
		OATPChargesPost OATPChargesPost;
		OATPChargesPost = new OATPChargesPost();
		return OATPChargesPost;
	}

}
I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Thank you for your valuable suggestion.

    When we create journal through MCRLedgerJournal_VendInvoiceRegister class as shown in above code the Approver field is set to current worker by default on ledgerJournalTable.

    Whereas when we create the journal manually the Approver field is set to blank.Therefore setting the Approver field to blank using x++ code helped me to open form in editable mode.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    If the journal is editable when you create it manually then you can compare that Journal with your journal created via code and see what is missing . Also use <> button from rich formatting to paste your code.

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    I suggest you create a similar journal in the user interface, and compare in table browser / SQL Server what is different in the data that you create in x++. Assuming it works differently when creating from x++ vs UI.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans