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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

New form using InMemory not populating data from caller

(4) ShareShare
ReportReport
Posted on by 293
I’m passing records from an existing form to a new form. 
Existing form: ProjSalesItemReq
New form: DIReturnItems
The new form is in the pattern Dialog-FastTabs and contains a grid an Ok and Cancel buttons.
The problem is that the records that I’m selecting from the existing form, does not appear on my new form, until I hit the Cancel button.  When the new form (DIReturnItems) opens, the grid is empty, and when I hit the cancel button, the records appear, and the form is not Cancelled. The Cancel button is the normal Cancel command button.
I’ve extended the ProjSalesItemReq form to include a button that calls the DIReturnItems form.
Here is the code behind the clicked event (I build a container with SalesLine RecIds):
[ExtensionOf(formControlStr(ProjSalesItemReq,DIReturnItems))]
final class ProjSalesItemReqDI_Extension
{

    //Get the selected records
    public void clicked()
    {
        int         recordsCount;
        SalesLine               salesLine;//SalesTable  salesTable;
        container   con;
        Args        args;
        str         multiSelectString;
        FormControl             formButtonControl = any2Object(this) as FormControl;
        FormDataSource          salesLine_ds = formButtonControl.formRun().dataSource(tableStr(SalesLine));

        args = new Args();

        recordsCount = salesLine_ds.recordsMarked().lastIndex();
        salesLine= salesLine_ds.getFirst(1);

        while(salesLine)
        {
            con = conIns(con,1, salesLine.RecId);

            multiSelectString = con2Str(con,',');

            salesLine= salesLine_ds.getNext(); 
        }
   
        args.parm(multiSelectString);

        new MenuFunction(menuitemActionStr(DIReturnItems), MenuItemType::Action).run(args);
        next clicked();
    }

}
 


The DIReturnItems form’s datasource is a temp table (of type InMemory), which receives the SalesLine recIds, and populates a temp table.
On the init of the DIReturnItems form, I receive the container and populate the temp table, herewith the code:
    public void init()
    {
        container   con;
        DIReturnItemsListTemp    returnItemListTmp;
        SalesLine   salesLine;
        int         iCnt;
        
        super();

        multipleRecords = element.args().parm();
        con = str2con(multipleRecords,',');

        for(iCnt = 1;iCnt<= conLen(con) ;iCnt++)
        {
             salesLine = salesLine::findRecId(conPeek(con,iCnt));

            returnItemListTmp.SalesId = salesLine.SalesId;
            returnItemListTmp.ItemName = salesLine.itemName();
            returnItemListTmp.ItemId = salesLine.ItemId;
            returnItemListTmp.UpdateQty = salesLine.SalesQty;
            returnItemListTmp.OrigQty = salesLine.SalesQty;
            returnItemListTmp.SalesLineRefRecId = salesLine.RecId;
            returnItemListTmp.SalesTableRefRecId = SalesTable::find(salesLine.SalesId).RecId;
            returnItemListTmp.ProjId = salesLine.ProjId;
            returnItemListTmp.insert();
        }

        DIReturnItemsListTemp.setTmpData(returnItemListTmp);

    }
 


The data is populated, but only when clicking the Cancel button.
My question is, why is the data only refreshed, or shown on the Cancel click?  What is happening behind the Cancel button that is refreshing the form to show the data?
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at
    I recommend throwing away all the code in clicked(). Instead, use a menu item button and set its Data Source property to SalesLine.
     
    In DIReturnItems form, create a method that takes the value from this.args().record(), use MultiSelectionHelper class to fetch the selected lines and create records in your TMP table.
     
    Potentially, you can write data directly to diReturnItemsListTemp buffer.
     
    Is executeQuery() method of DIReturnItemsListTemp DS called when you open DIReturnItems form?
  • Suggested answer
    Sankar Ramalingam Profile Picture
    262 on at
    Refer this blog https://dynamicsaxinsight.com/2014/08/20/ax-2012-using-temporary-table-as-forms-datasource/. Put the data insert logic in a separate method and call it in  form init() method.
     
    DIReturnItemsListTemp.setTmpData(element.populateRecords())

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans