Run a form with predefined key

TomasTomas Member Posts: 420
I have a custom form with a button on it. When I click a button, I want to open Item List form, where data is sorted according to Seach Code.

I would imagine this code should solve my question:
Item.RESET;
Item.SETCURRENTKEY("Search Code");

ItemListForm.SETTABLEVIEW(Item);
ItemListForm.RUN;

However, this only works if SourceTableView is not defined. If there is a key defined in SourceTableView property, then this code is useless. Is there any other way of defining a sorting key and forcing it over a predefined key on SourceTableView property?

Thanks for ideas!

Answers

  • i4tosti4tost Member Posts: 208
    Create procedure within this form and by using it store global variable value. Then in triger OnOpenForm change the key
    Hope its clear
  • rrvanzylrrvanzyl Member Posts: 21
    Hi Tomas,

    I quickly did the following;

    1. Added a new button to a form and added the following to the OnPush trigger:
    OnPush
    Local Var: Item Record: Table 27 Item
    Local Var: ItemList Form: Form 31 Item List

    //Code...
    Item.SETCURRENTKEY("Search Description");

    CLEAR(ItemList);
    ItemList.SetKey(Item);
    ItemList.RUNMODAL;

    2. On the Item List form I added the following function: SetKey and a Global Variable GlobItem

    3. The SetKey function looks like this...
    Setkey(VAR pItem : Record Item)
    //Code...
    GlobItem.SetView(pItem.GetView);

    4. On the OnOpen trigger add the following code
    OnOpen
    IF GlobItem.CURRENTKEY <> CURRENTKEY THEN
    SETVIEW(GlobItem.GETVIEW);

    I hope this helps ;-)

    Cheers,
    R
  • ritesh.singhritesh.singh Member Posts: 123
    I tried this and it works...
    Item.RESET;
    Item.SETCURRENTKEY("Search Description");
    IF Item.FINDFIRST THEN
    ItemList.SETTABLEVIEW(Item);
    ItemList.RUN;
    Thanks,
    Ritesh K Singh
  • TomasTomas Member Posts: 420
    I tried this and it works...
    Item.RESET;
    Item.SETCURRENTKEY("Search Description");
    IF Item.FINDFIRST THEN
    ItemList.SETTABLEVIEW(Item);
    ItemList.RUN;

    This works ONLY when we do not have SourceTableView property defined to something like SORTING(No.).
  • TomasTomas Member Posts: 420
    i4tost wrote:
    Create procedure within this form and by using it store global variable value. Then in triger OnOpenForm change the key
    Hope its clear

    Thanks (ačiū), that is the way I went forward.
  • DenSterDenSter Member Posts: 8,304
    edited 2009-02-19
    Tomas wrote:
    ačiū
    Gesundheit :mrgreen:

    <edit>corrected spelling, with my apologies to all the German speaking peoples of the world :mrgreen: </edit>
  • garakgarak Member Posts: 3,263
    DenSter wrote:
    Tomas wrote:
    ačiū
    Gesuntheit :mrgreen:

    Daniel, Gesundheit you must write with an "d" not with an "t" :mrgreen:
    @Thomas: Gesundheit (Bless you)
    Do you make it right, it works too!
  • themavethemave Member Posts: 1,058
    Tomas wrote:
    I have a custom form with a button on it. When I click a button, I want to open Item List form, where data is sorted according to Seach Code.

    I would imagine this code should solve my question:
    Item.RESET;
    Item.SETCURRENTKEY("Search Code");
    
    ItemListForm.SETTABLEVIEW(Item);
    ItemListForm.RUN;
    

    However, this only works if SourceTableView is not defined. If there is a key defined in SourceTableView property, then this code is useless. Is there any other way of defining a sorting key and forcing it over a predefined key on SourceTableView property?

    Thanks for ideas!
    This may be a dumb question, but this is your custom form, you want it to sort this special way, then why are you setting the SoruceTableView in the first place, why not just use the code suggested, and not define the SoruceTableView on the form ?
Sign In or Register to comment.