Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Method CloseOK

(0) ShareShare
ReportReport
Posted on by 105

Hi everyone,

I add a form with datasource CustConfirmJour and add a combobox with  field(language)  and checbox(additional comment in report). When i change a language it's works but always print a SalesConfirm for the first SalesOrder.

Method Init

public void init()
{
    if(!element.args() || !element.args().record())
    {
         throw error("@SYS302");
    }

    super();

    if(element.args().record().TableId == tableNum(CustConfirmJour))
    {
        CustConfirmJourLocal = element.args().record();
    }



}

Method closeOK
public void closeOk()
{
    Args                args             = new Args();
    RecordSortedList    journalList      = SalesConfirmJournalPrint::construct().newJournalList();


    for (CustConfirmJourLocal = getFirstSelection(custConfirmJour_ds);
         CustConfirmJourLocal;
         CustConfirmJourLocal = custConfirmJour_ds.getNext())
    {
 journalList.ins(CustConfirmJourLocal);}

        journalList.first(CustConfirmJourLocal);

args.record(CustConfirmJourLocal);

    new MenuFunction(menuitemOutputStr(SalesConfirmation), MenuItemType::Output).run(args);

super();
}


*This post is locked for comments

  • Verified answer
    Krychul Profile Picture
    Krychul 105 on at
    RE: Method CloseOK

    Thank's you all for help.

    I add this code to the method init in DataSourcea and work's.

    public void init()
    {
        QueryBuildDataSource  queryDataSourceLink;
        ;
    
        super();
    
        if (element.args().dataset() == tablenum(CustConfirmJour))
        {
            this.query().dataSourceTable(tablenum(CustConfirmJour)).clearDynalinks();
    
            queryDataSourceLink = this.query().dataSourceTable(tablenum(CustConfirmJour)).addDataSource(tablenum(CustConfirmSalesLink));
            queryDataSourceLink.relations(true);
            queryDataSourceLink.addDynalink(fieldnum(CustConfirmJour, ConfirmId),
                                            element.args().record(),
                                            fieldnum(CustConfirmJour, ConfirmId));
        }
    }


  • Yunus Shaik Profile Picture
    Yunus Shaik 330 on at
    RE: Method CloseOK

    Put a breakpoint on main method of SalesConfirmController class and check values of passed args.

    Debug and check where value is getting reset to first record.

  • Krychul Profile Picture
    Krychul 105 on at
    RE: Method CloseOK
    public void closeOk()
    {
        Args                args             = new Args();
        RecordSortedList    journalList      = SalesConfirmJournalPrint::construct().newJournalList();
    
       MultiSelectionHelper helper = MultiSelectionHelper::construct();
        helper.parmDatasource(custConfirmJour_ds);
        CustConfirmJourLocal = helper.getFirst();
     while (CustConfirmJourLocal.RecId != 0)
        {
            info(CustConfirmJourLocal.SalesId);
            journalList.ins(CustConfirmJourLocal);
            CustConfirmJourLocal = helper.getNext();
        }
    
    
    
           // journalList.first(CustConfirmJourLocal);
    
    args.object(journalList);
    
        new MenuFunction(menuitemOutputStr(SalesConfirmation), MenuItemType::Output).run(args);
    
    super();
    }

    Display the same error.

    When i comment journalList.first(CustConfirmJourLocal) work but still print a SalesOrder S0000002. I select a SalesOrder S00000512

  • Yunus Shaik Profile Picture
    Yunus Shaik 330 on at
    RE: Method CloseOK

    Move the journalList.ins(CustConfirmJourLocal) statement before helper.getNext() statement statement inside loop

  • Krychul Profile Picture
    Krychul 105 on at
    RE: Method CloseOK

    When i use this code

    public void closeOk()
    {
        Args                args             = new Args();
        RecordSortedList    journalList      = SalesConfirmJournalPrint::construct().newJournalList();
    
    
       MultiSelectionHelper helper = MultiSelectionHelper::construct();
        helper.parmDatasource(custConfirmJour_ds);
        CustConfirmJourLocal = helper.getFirst();
     while (CustConfirmJourLocal.RecId != 0)
        {
            info(CustConfirmJourLocal.SalesId);
            CustConfirmJourLocal = helper.getNext();
        }
    
     journalList.ins(CustConfirmJourLocal);
    
            journalList.first(CustConfirmJourLocal);
    
    args.object(journalList);
    
        new MenuFunction(menuitemOutputStr(SalesConfirmation), MenuItemType::Output).run(args);
    
    super();
    }

    I have this error

    7418.ax.jpg

  • Yunus Shaik Profile Picture
    Yunus Shaik 330 on at
    RE: Method CloseOK

    In the above code, you are selecting only the first marked record using helper.getFirst()

    To select the other marked records, you have to run a loop and use helper.getNext() to get the next marked record.

    You can find this in the link which i posted with my previous comment.

  • Krychul Profile Picture
    Krychul 105 on at
    RE: Method CloseOK

    In init metod i deleted this code.

    I Tried to use MultiSelectionHelper and always select the same Sales Order I don't know why.

    public void closeOk()
    {
        Args                args             = new Args();
        RecordSortedList    journalList      = SalesConfirmJournalPrint::construct().newJournalList();
    
    
       
       MultiSelectionHelper helper = MultiSelectionHelper::construct();
        helper.parmDatasource(custConfirmJour_ds);
        CustConfirmJourLocal = helper.getFirst();
    
    
    
     journalList.ins(CustConfirmJourLocal);
    
            journalList.first(CustConfirmJourLocal);
    
    args.object(journalList);
    
        new MenuFunction(menuitemOutputStr(SalesConfirmation), MenuItemType::Output).run(args);
    
    super();
    }

    I use a similar code to the CustInvoiceJour and it's works.

  • Yunus Shaik Profile Picture
    Yunus Shaik 330 on at
    RE: Method CloseOK

    Hi Krychul,

    Try using MultiSelectionHelper class to select marked records.

    You can find an example in the below link:

    community.dynamics.com/.../get-select-records-by-multiselectionhelper-class

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Method CloseOK

    You need to debug you method and look if all your marked records are selected and added to journalList.ins(CustConfirmJourLocal); then you need to check if correct record is selected in  journalList.first(CustConfirmJourLocal);

    and why do you need

    if(element.args().record().TableId == tableNum(CustConfirmJour))

       {

           CustConfirmJourLocal = element.args().record();

       }

    in init method ?

  • Krychul Profile Picture
    Krychul 105 on at
    RE: Method CloseOK

    When i mark or not mark records always print SalesConfrim from  SalesOrder(SO0000002)

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

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans