Showing posts with label General Journal. Show all posts
Showing posts with label General Journal. Show all posts

Wednesday, June 14, 2023

Open journal lines form from the custom form using x++.

 Open journal lines form from the custom form using x++.


  • We need to add ledgerJournalTable in the form data source and don't give any properties.
  • Copy the JournalLines_Review button from the LedgerJournalTable form.

Write the below code in the Form.

public class Form1 extends FormRun
{
    LedgerJournalFormTable  journalFormTable;

    public void init()
    {
        journalFormTable = LedgerJournalFormTable::construct(element);

        journalFormTable.datasourceInitPost(LedgerJournalTable);

        super();
    }

    JournalForm journalForm()
    {
        return journalFormTable;
    }
}


Button clicked method. (copied from LedgerJournalTable)
    [Control("MenuFunctionButton")]
    class JournalLines_Review
    {
        /// <summary>
        /// Handles the Lines->Review button's clicked event.
        /// </summary>
        public void clicked()
        {
            journalFormTable.assertJournalNotInUse();
    
            journalFormTable.parmIsProcessingPaymentOnApprovedJounal(false);
            journalFormTable.parmIsWFApprovedModeSelected(true);
    
            super();
    
            ledgerJournalTable_ds.reread();
        }

    }

The below code I have written in jumpRef method is based on my requirement.

    [Control("String")]
    class Table1_FieldString1
    {
        public void jumpRef()
        {
            super();

            LedgerJournalTable  ledgerJournalTableNew = LedgerJournalTable::find(Table1.FieldString1);


            //ledgerJournalTable_ds.setRecord(ledgerJournalTableNew);

            ledgerJournalTable_ds.findRecord(ledgerJournalTableNew);

            //ledgerJournalTable_ds.reread();
            //ledgerJournalTable_ds.refresh();

            journalFormTable.datasourceInitPost(ledgerJournalTable_ds.cursor());

            JournalLines_Review.clicked();
        }
    }


Another Way:

Keep daxing!!





Sunday, November 1, 2020

Import General Journals through Excel in AX 2012 X++


 Hi guys, Today we see how to Import General Journals through Excel in Ax 2012 using Excel.


Run the below job.

static void JournalImport(Args _args)

{

    Dialog                  _dialog;

    DialogField             _file;

    SysExcelApplication     application;

    SysExcelWorkbooks       workbooks;

    SysExcelWorkbook        workbook;

    SysExcelWorksheets      worksheets;

    SysExcelWorksheet       worksheet;

    SysExcelCells           cells;

    COMVariantType          type;

    Name                    name;

    FileName                filename;

    LedgerJournalACType     LedgerJournalACType;



    AxLedgerJournalTable    axLedgerJournalTable ;

    AxLedgerJournalTrans    axLedgerJournalTrans;


    container               accPattern,offSetPattern;

    int                     row = 1;


    str                     _Name;

    str                     _Description;

    AmountCurDebit          _Debit;

    str                     _LedgerDimension;

    str                     _OffsetAccountType;

    str                     _AccountType;

    str                     _OffsetLedgerDimension;



    axLedgerJournalTable = new AxLedgerJournalTable();


    axLedgerJournalTrans = new AxLedgerJournalTrans();


    _dialog = new Dialog("Import Data From Excel");

    _dialog.addText("Select file:");


    _file   = _dialog.addField(ExtendedTypeStr("FilenameOpen"));

    _dialog.run();


    if (_dialog.closedOK())

    {


        info(_file.value() );


    application = SysExcelApplication::construct();

    workbooks   = application.workbooks();

    //specify the file path that you want to read

    filename   =_file.value(); //ExcelSheet File Name

    try

    {

        workbooks.open(filename);

    }

    catch (Exception::Error)

    {

         throw error('File cannot be opened');

    }


    workbook    = workbooks.item(1);

    worksheets  = workbook.worksheets();

    worksheet   = worksheets.itemFromNum(1); //Here 1 is the worksheet Number

    cells       = worksheet.cells();

    do

    {

        row++;

        _Name                       = cells.item(row, 1).value().bStr();

        _Description                = cells.item(row, 2).value().bStr();

        _Debit                      = cells.item(row, 3).value().double();

        _OffsetAccountType          = cells.item(row, 5).value().bStr();

        _AccountType                = cells.item(row, 6).value().bStr();



        axLedgerJournalTable.parmJournalName(_Name);


        axLedgerJournalTable.save();


        axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);


        axLedgerJournalTrans.parmTransDate(systemDateGet());

        axLedgerJournalTrans.parmCurrencyCode('USD');

        axLedgerJournalTrans.parmTxt(_Description);

        axLedgerJournalTrans.parmAmountCurDebit(_Debit);

        axLedgerJournalTrans.parmExchRate(Currency::exchRate('USD'));

        axLedgerJournalTrans.parmAccountType(str2enum(LedgerJournalACType,_AccountType));



        accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

        axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));



        offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

        axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetPattern));


        axLedgerJournalTrans.save();


        type = cells.item(row+1, 1).value().variantType();

    }


        while (type != COMVariantType::VT_EMPTY);

        application.quit();

        info(strFmt("Journal %1 created", axLedgerJournalTable.ledgerJournalTable().JournalNum));

        info("Data is Imported");

    }

    }


Keep Daxing!!

How to Create a General Journal line in D365 FO or Ax 2012 using X++

 

Hi guys, Today we see how to create General Journal line in Ax 2012 or D365 FO.


Here we are using 2 classes.


    AxLedgerJournalTable    axLedgerJournalTable ;

    AxLedgerJournalTrans    axLedgerJournalTrans;


        axLedgerJournalTable.parmJournalName(_Name);

        axLedgerJournalTable.save();


       axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);

        axLedgerJournalTrans.parmTransDate(systemDateGet());

        axLedgerJournalTrans.parmCurrencyCode('USD');

        axLedgerJournalTrans.parmTxt(_Description);

        axLedgerJournalTrans.parmAmountCurDebit(_Debit);

        axLedgerJournalTrans.parmExchRate(Currency::exchRate('USD'));

        axLedgerJournalTrans.parmAccountType(str2enum(LedgerJournalACType,_AccountType));

        accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

        axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));

        offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

        axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetPattern));


        axLedgerJournalTrans.save();


Keep Daxing!! 

Tuesday, September 29, 2020

Post Button enabling or disabling for Journals in ax 2012 using X++

 Hi guys, Today we see how to disable post button in journals form in Ax 2012 using X++.


            In LedgerJournalTable form i want to disable the post button for particular user group persons.



  Go to LedgerJournalFormTable class in enableButtonsActive method write following code.

           while select userGroupList
                     where userGroupList.groupId == "Test Group"
                             && userGroupList.userId == curUserId()
                          {

                              ctrlPostJournalMenu.enabled(false);
                           }




Keep Daxing!!