Simple method in Form AOT

This question is answered

I am testing on how to bring a new field from another table into a form, using a method.

display ItemName testme2()

{

   InventTable inventTable;

   ProdCalcTrans PCT;

   ;

   return (select firstonly ItemName from inventTable

       index hint ItemIdx

       where inventTable.ItemId == PCT.Key1).ItemName;

}

There are no errors or warnings returned when compiled. Although the same query works in another method, the one above returns no values.

Any ideas why?

Thank you,

Verified Answer
  • Use debugger to see whether your method is call in the first place, what value it in PCT.Key1/this.Key1 and what the select returns. Identify what doesn't work as you expect and if you fail to figure out what's wrong, return back here and tell us all relevant details.

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

All Replies
  • You never set PCT variable, therefore PCT.Key1 is empty and the query tries to find InventTable without ItemId, which can't succeed because ItemId is mandatory.
    You should probably place the method on ProdCalcTrans table and find InventTable by this.Key1.

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

  • I have it in ProdCalcTrans table. Key1 is a field from ProdCalcTrans and PCT is defined above. Sorry you got me a bit confused. Would you be able to give me an example?

  • I see that's PCT is defined above and never assigned, that's exactly the problem. You would have to assign a value to the variable (select statement, find() method or so) to get that code working. But if you want to Key1 of the current ProdCalcTrans record, remove PCT variable completely and just use where inventTable.ItemId == this.Key1.

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

  • Any idea why the following code would work?

    display ItemName itemResourceName()

    {

       InventTable         inventTable;

       WrkCtrTable         wrkCtrTable;

       CostSheetNodeTable costSheetNodeTable;

       ProdCalcTrans       prodCT;

       ;

       switch (prodCT.CalcType)

       {

           case ItemCalcType::Production:

           case ItemCalcType::Item:

           case ItemCalcType::BOM:

           case ItemCalcType::Service:

               select firstonly ItemName from inventTable

                   index hint ItemIdx

                   where inventTable.ItemId == prodCT.Key1;

               return inventTable.ItemName;

           case ItemCalcType::Setup:

           case ItemCalcType::Process:

           case ItemCalcType::Qty:

               select firstonly Name from wrkCtrTable

                   index hint WrkCtrNumIdx

                   where wrkCtrTable.WrkCtrId == prodCT.Key1;

               return wrkCtrTable.Name;

           case ItemCalcType::IndirectSurcharge:

           case ItemCalcType::IndirectRate:

               select firstonly Description from costSheetNodeTable

                   where costSheetNodeTable.Code == prodCT.Key1

                      && costSheetNodeTable.SheetId == CostSheetTable::defaultCostSheetTable().SheetId;

               return costSheetNodeTable.Description;

       }

       return '';

    }

  • Did not work replacing with this.Key1. No errors/warnings but also nothing returned.

  • Use debugger to see whether your method is call in the first place, what value it in PCT.Key1/this.Key1 and what the select returns. Identify what doesn't work as you expect and if you fail to figure out what's wrong, return back here and tell us all relevant details.

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

  • I will install debugger on one of the aos's. In the meantime I used a print statement to view result and it returns blank. I will come back after debugger is installed. Thanks

  • Hello,

    I started from the beginning and both versions of the method are working. Not sure what was wrong. Didn't even get to run the debugger although now I have it setup for next time.

    Thank you.