Showing posts with label Temp table. Show all posts
Showing posts with label Temp table. Show all posts

Monday, July 11, 2022

How to populate data in form with temp table data source using X++ In D365FO

 How to populate data in form with temp table data source using X++ In D365FO.

Here I am using RecordInsertList to insert data in Temp table.

  • I have added temp table in form.
  • In Form init method I am inserting data into temp table.
  • Using linkPhysicalTableInstance I have assigned to temp table buffer to data source.

Form Init method:

[Form]
Public void init()
{
    CustTable  custTable = element.args().record(); 

    MyTempTable.linkPhysicalTableInstance(MyTempTable::getTempTable(custTable)); // add tempTable instance
 
}
[Table method]

Public static MyTemptable getTempTable(CustTable  _custTable)

{
    MYTempTable         myTempTable;
    SalesTable          salesTable;
    RecordInsertList    tempRecordInsertList = new RecordInsertList(tableNum(MYTempTable),
                                                                     true, true, true, 
                                                                     false, true, myTempTable);
    while select salesTable
       where salesTable.CustAccount == _custTable.CustAccount 	
    {
        myTempTable.clear();
        myTempTable.CustAccount = salesTable.CustAccount;
        myTempTable.SalesId     = salesTable.SalesId;

        tempRecordInsertList.add(myTempTable);
    }

    tempRecordInsertList.insertDatabase();

    return myTempTable;
}

If you want to write select / while select statement for temp table follow the below logic. 
    MyTempTable    MyTempTableLoc; 
    MyTempTableLoc.linkPhysicalTableInstance(MyTempTable);// temp table buffer from init method.
    select MyTempTableLoc where 'your condition';
    while select myTempLoc
    {
        // your logic
    }
Keep Daxing!!

Tuesday, December 28, 2021

Passing Temp table values from one form to other form in D365fo using X++

Hi guys, today post is for passing Temp table values from one form to other form using List in D365fo.

I got requirement like I need to pass the selected temp table values from one form to other form and I need to do some actions based on temp table values. 

For this we can use 

  • List
  • Set
  • Container
Examples: Use any one from this.
-----------------------------------------------------------------------------------------------------------------------------
List: 

//Parent Class Button Clicked method.

void clicked() {

    List myList; TempTable tmpLoc; ; myList = new List(Types::Record);     if (TempTable_ds.Anymarked())// check user selected the record or not. for (tmpLoc = getFirstSelection(TempTable_ds); tmpLoc; tmpLoc = TempTable_ds.getNext()) { myList.addStart(tmpLoc); }

//Calling child form: Any one we can use.

Way1: Args args; FormRun formRun; args = new Args(); args.parmobject(myList); args.name(formstr(Myform)); formrun = classfactory.formrunclass(args); formrun.init(); formrun.run(); formrun.wait();

Way 2:

    Args args;

    args.parmObject(myList);

    new MenuFunction(menuitemdisplaystr(menu item name), MenuItemType::Display).run(args);

}

 //Child class init method;

public void init() {

    List myList; ; if (element.args().parmObject()) { myList = element.args().parmObject(); } //Iterator ListIterator listterator = new ListIterator(myList); while (literator.more()) { tmpTable.data(literator.value()); } //Enumerator ListEnumerator enumerator = myList.getEnumerator(); while(enumerator.moveNext()) { tmpTable.data(enumerator.current()); }

}

-----------------------------------------------------------------------------------------------------------------------------

Set:

//Parent Class Button Clicked method.

void clicked() {

    Set records; TempTable tmpLoc; ; records = new Set(Types::Record); for (tmpLoc = getFirstSelection(TempTable_ds); tmpLoc; tmpLoc = TempTable_ds.getNext()) { records.add(tmpLoc); }

//Calling child form: Any one we can use.

Way1:

Args args; FormRun formRun; args = new Args(); args.parmobject(records); args.name(formstr(Myform)); formrun = classfactory.formrunclass(args); formrun.init(); formrun.run(); formrun.wait();

Way 2:

    Args args;

    args.parmObject(myList);

    new MenuFunction(menuitemdisplaystr(menu item name), MenuItemType::Display).run(args);

}

//Child class init method; 

public void init() {

    Set records; ; if (element.args().parmObject()) { records = element.args().parmObject(); } //Iterator SetIterator recordsIterator = new SetIterator(records);//element.args().parmObject() while (recordsIterator.more()) { tmpTable.data(recordsIterator.value()); //tmpTable.linkPhysicalTableInstance(recordsIterator.value()); recordsiterator.next(); } //Enumerator SetEnumerator enumerator= records.getEnumerator(); while (enumerator.moveNext()) { tmpTable.data(enumerator.current()); }

}

-----------------------------------------------------------------------------------------------------------------------------

Container:

//Parent Class Button Clicked method. 

void clicked() {

    container                   packed;
    Set                         records;
    TempTable                   tmpLoc;
    ContainerClass              containerClass;// For container we need to use this.
    ;
    
    records = new Set(Types::Record);
    for (tmpLoc = getFirstSelection(TempTable_ds); tmpLoc; tmpLoc = TempTable_ds.getNext())
    {
        records.add(tmpLoc);
    }

    packed          = records.pack();
    containerClass  = new ContainerClass(packed);
    

//Calling child form: Any one we can use.

Way1:

    Args           args;
    FormRun        formRun;

    args = new Args();
    args.parmobject(containerclass);
    args.name(formstr(Myform));

    formrun = classfactory.formrunclass(args);

    formrun.init();
    formrun.run();
    formrun.wait();

Way 2:

    Args args;

    args.parmObject(myList);

    new MenuFunction(menuitemdisplaystr(menu item name), MenuItemType::Display).run(args);

}

//Child class init method:

public void init() {
    ContainerClass containerClass; ; if (element.args().parmObject()) { containerClass = element.args().parmObject(); } SetIterator recordsIterator; container packed = containerClass.value(); ; recordsIterator = new SetIterator(Set::create(packed)); while (recordsIterator.more()) { tmpTable.data(recordsIterator.value()); //tmpTable.linkPhysicalTableInstance(recordsIterator.value()); recordsiterator.next(); }
}
--------------------------------------------------------------------------------------------

Keep Daxing!!