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!!

No comments:

Post a Comment