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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Mea_ Profile Picture
    60,286 on at

    You are not changing anything in this code. what are you trying to achieve ?

  • Krychul Profile Picture
    105 on at

    In this case i want to print a SalesConfirm from the SalesOrder that i chose(for example SO0002555) but always print a SalesConfirm from a SalesOrder(SO0000002)

  • Mea_ Profile Picture
    60,286 on at

    You can use args.object(journalList) instead of args.record(CustConfirmJourLocal); to print all selected records.  However I don't see any issue with your code it should select all marked records and add them to journalList. After it should pick first.

    However if did not mark any records getFirstSelection() will return selected record. maybe thats the issue ?

  • Krychul Profile Picture
    105 on at

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

  • Mea_ Profile Picture
    60,286 on at

    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 ?

  • Yunus Shaik Profile Picture
    330 on at

    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

  • Krychul Profile Picture
    105 on at

    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
    330 on at

    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
    105 on at

    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
    330 on at

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#1
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#1
Pratik Bhosle Profile Picture

Pratik Bhosle 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans