2

Ok I did it. It works fine. Thanks for help. Here is my code. Now I only need to call my command button in a differend form to disable it and create a info there. Anyone could look about it ? In my code I got reference errors.

[ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
final class ProdParmReportFinishedActiveWG_Extension
{

 public int active()
{
    int ret;
    next Active();

    {
        ProdTable tableBuffer = this.cursor();
        ProdTable prodtable;


        if(tableBuffer.ProdId == tableBuffer.CollectRefProdId
             && tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
            {
               select firstonly RecId,ProdId from ProdTable where
            ProdTable.CollectRefProdId == tableBuffer.ProdId
             && ProdTable.Prodstatus != ProdStatus::ReportedFinished
                && tableBuffer.RecId != prodtable.RecId;
            {
                    Global::info(strFmt("%1 , %2",
            prodtable.prodid, prodtable.recid));

                    // FormButtonControl mybutton = this.FormRun().design().controlname(formControlStr(ProdParmReportFinished, Ok)) as FormButtonControl;
                    //  mybutton.enabled(false);
            }

        }
        else
        {

            Global::info(strFmt("%1 , %2, %3, %4",
            tableBuffer.prodid, tableBuffer.CollectRefProdId, tableBuffer.InventRefType, tableBuffer.ProdStatus));
        }

    }
    return ret;
}

}
Tweene
  • 257
  • 4
  • 16

1 Answers1

2

"I want to use this code everytime user changes his actual row but instead it runs just once and apply to all my rows."

Use the selectionChanged() method instead of active().

In fact most use cases where you think you should use active(), you're probably looking for selectionChanged() (or the OnSelectionChanged event for handlers) instead.

ztirom
  • 4,382
  • 3
  • 28
  • 39
rjv
  • 1,058
  • 11
  • 29
  • As for extension should I use fromstr or formdatasoucestr in my final class ? And second question how can I use this current row for my select statement ? I need to check the rows that are selected – Tweene Feb 05 '20 at 13:30
  • 1
    Always use x++ compile time functions such as formdatasourcestr() to ensure compile time checking for accessing formrun and formdatasource objects correctly. To loop through marked grid records, use this MultiSelectionHelper class. Either MultiSelectionHelper::createfromcaller() or MultiSelectionHelper::construct with parmFormDatasource() depending on your scenario. – rjv Feb 05 '20 at 14:02
  • Could you show me a code sample ? Im new in x++ so it's really hard for me to code new things like this. First I need to check if user pointed a row that RefID = ProdID after that it's more simple ( I think?) only then I need to check all RefID that hat the same ProdID but have different ProdID ( 1 RefID has always 1 the same ProdID and some other ProdID's) – Tweene Feb 05 '20 at 14:12
  • 1
    "if a user pointed a row" I assume that you mean fire the OnSelectionChange event. Find the datasource of the grid and create a new event handler for that event. Then loop through all records of the table that you need to compare to the current formdatasource.cursor() record. – rjv Feb 05 '20 at 14:18
  • This datasource grid is in different form ProdTableListPage. So I need to create 2 final classes ? One for this ListPage and one for ProdParm? Or I can run the code from one final class I need to check in ListPage but the actual change need to be done in ProdParm ( just disable OK button and add a warning label). – Tweene Feb 05 '20 at 14:30
  • I don't fully understand your scenario. A final class is simply one that cannot be further inherited from/extended. You likely need to extension classes OR two handler classes for each of your forms. On the selectionChanged of the child form, you would use MultiSelectionHelper::createfromCaller(args.caller()) to loop through the marked records of the parent grid. – rjv Feb 05 '20 at 14:44
  • My task is to create a verify extension for production control BOM. So ( I think) first I need is to check if the current selected row in grid is the main task (ProdId=RefID) if its true check all other tasks that have this RefID if their ProdStatus is reported as finished. If it's not disable 'Ok' button in ProdParm so noone can proceed the whole BOM. It's all because users forget to change this flag on tasks and try to report it all as finished. – Tweene Feb 05 '20 at 14:58