Form to display newest records only

I’m trying to create a form that I can use to display a item prices where only the newest (we right now don’t mind that a furture price could be set) price for each price group / currency. The idea is to display this as a subform to the items. I know it’s possible, I was just wondering if someone have tried it. I think it’s someting with the onNextRecord (and on onFindRecord). Best regards, Erik P. Ernst, webmaster Navision Online User Group

You could add a new field to the table to mark each record as the newest and then set a filter on this field when showing the records ? But this will include some coding for the Insert/Modify/Delete… Otherwise you cold make a form running on a temporary table, snd select the records to show when opening the form. Take a look at Navigate (Form 344) where this is used…

You’re a bit scarce on info about the setup of the pricing here (separate table? Single price only or ‘historical’ overview?), but nevertheless I would say: - Use a subform indeed. - Set the SubFormView to sort descending on date (latest first), assuming you have a date field in the prices table. - Set the SubFormLink to select the proper price record, based on Item (Group) ID and currency fields. In fact, if there’s only one price valid for a Item Group, this would be sufficient already. This will provide an automatic update of the price record when browsing the items. John

You’re rigth so far that I plan to put it into a sub table on the item card. It’s simply the standard item price group tables (Item No., Price Group Code, Currency, Start Date, Price). I.e. I have a item with 6 price records: RETAIL, ‘’, 010101, 20.00 RETAIL, ‘’, 020201, 22.00 RETAIL, USD, 011501, 2.50 WHOLESALE, ‘’, 0D, 14.00 WHOLESALE, ‘’, 010101, 15.00 WHOLESALE, ‘’, 020201, 13.00 Then these records are what should be displayed: RETAIL, ‘’, 020201, 22.00 RETAIL, USD, 011501, 2.50 WHOLESALE, ‘’, 020201, 13.00 Best regards, Erik P. Ernst, webmaster Navision Online User Group

I have done it couple weeks ago. The best solution for it is use matrix form. So you need: 1. matrix form: item No/Price group code 2. in form heading, fields: current date, Currency 3. func to calc price depending on current date & currency: GetPrice(…):dec; t.Setrange(currency,currency); t.Setrange(“Start date”,0D,“current date”); t.Find(’+’); Exit(t.Price) 4. In TextBox of matrix for showing use value cPrice:Decimal 5. You need use trigers: TextBox: OnActivate: cPrice:=GetPrice(…); MatrixBox: OnAfterGetRecord: cPrice:=GetPrice(…); You can add buttons to navigate through dates like in G/L Projects; Keep in mind, that if your matrix box will be editable, you will get bug of refreshing. I was writed about that earlier in this forum.

Oh yes, this one will do this - I think. Thanks. Best regards, Erik P. Ernst, webmaster Navision Online User Group

This wasn’t still exactly what I was looking for. At least it doesn’t really work. The thing is that I only want to display the active price groups, that is the price groups with a active price for the current item. Best regards, Erik P. Ernst, webmaster Navision Online User Group

believe me, it works, just you need be more patient. Solution No 2: You have two alternatives: A) use tempory table … form 344… B) use different tables for navigating and showing. We will continue variant B: let it be subform, so Setrange(“item No”,…) was set by link;


OnFindRecord(Which)
t:=Rec;
IF NOT t.MyFIND(Which) THEN EXIT(FALSE);
Rec:=t;
EXIT(TRUE);

OnNextRec(Steps)
t:=Rec;
i:=t.MyNEXT(Steps);
IF i<>0 THEN Rec:=trec;
EXIT(i);

//in table make func.
MyFind(Which)
SetCurrentKey(Item No., Price Group Code, Currency, Start Date);
IF find(Which) THEN  
  BEGIN
    Setrange("Price grooup","Price grooup");
    Setrange(Currency,Currency);
    FIND('+');
    Setrange("Price grooup");
    Setrange(Currency);
    EXIT(TRUE);
  END ELSE EXIT(FALSE);

MyNEXT(Steps)
SetCurrentKey(Item No., Price Group Code, Currency, Start Date);
MySteps:=Steps;
StepsMaded:=0;
IF (steps<0) THEN 
BEGIN
  Repeat
    Setrange("Price grooup","Price grooup");
    Setrange(Currency,Currency);
    FIND('-');
    Setrange("Price grooup");
    Setrange(Currency);
    StepsMaded:=NEXT(-1);
    MySteps-=StepsMaded;
  UNTIL (Steps=MySteps)OR(StepsMaded=0);
END ELSE BEGIN
  Repeat
    Setrange("Price grooup","Price grooup");
    Setrange(Currency,Currency);
    FIND('+');
    Setrange("Price grooup");
    Setrange(Currency);
    StepsMaded:=NEXT(1);
    MySteps-=StepsMaded;
  UNTIL (Steps=MySteps)OR(StepsMaded=0);
  Setrange("Price grooup","Price grooup");
  Setrange(Currency,Currency);
  FIND('+');
  Setrange("Price grooup");
  Setrange(Currency);
END;
EXIT(MySteps);

Sorry if maded some mistakes, I don’t tested it. There is not valid code, but only idea explained in code