[SOLVE] How return value to a parent form

SFZ_GregSFZ_Greg Member Posts: 6
When you are on the "Item Card Form". I disable the "No." and i put a button to load a form "Update Number Item". This form load different Part of the number on dropdownlist :

Example :
Form Item Card :
No. : BRRF30XXXX0150XXXX
....

Form Update Number Item :
No. Before : BRRF30XXXX0150XXXX
Area1 : BRR
Area2 : F
Area3 : 30
Area4 : XXXX
Area5 : 0150
Area6 : XXXX
No. After : BRRF30XXXX0150XXXX

You can change the different value of dropdownlist (the value of each dropdownlist are on a table of course)

Ex :
No. Before : BRRF30XXXX0150XXXX
Area1 : BRR
Area2 : H
Area3 : 20
Area4 : XXXX
Area5 : 0150
Area6 : XXXX
No. After : BRRH20XXXX0150XXXX

And when they validate the form i run :
It.SETCURRENTKEY("No.");
It.SETFILTER("No.",CodeItem);
It.FIND('-');
It.DELETE;
CodeFin := Codetemp;
It."No." := Codetemp;
CaptFin := Descriptemp;
It.Description := Descriptemp;
It.INSERT;
It.GET(It."No.");
MESSAGE('L''Article '+CodeItem+' a été renommé '+It."No.");

That Update the Item Table !

But when i go back to the Item Card i'm not on the Item i just modify but on the next one on the list before i modify it !

I don't know how to return a value a record Item or the number of Item to go back on the modify Item ? How can i do that ?

Comments

  • MTCMTC Member Posts: 159
    It's a bit difficult for me to see what you are actually doing TBH and where you are actually doing it. If you are running the second form in a modal manner, then the basic way to get values out of it (going by the thread title) is that it should have a/some global variable(s) that store what it did or the state it ended up in, and you can put in an access function (interface) to get what that value was:

    UpadatingForm.RUNMODAL; // However you want to run it

    ReturnValue := UpdatingForm.AccessFunction();

    // Do what you want with returned value.
  • SFZ_GregSFZ_Greg Member Posts: 6
    I put an image :

    http://computerz.free.fr/temp/UpdateNumberItem.JPG
    UpadatingForm.RUNMODAL; // However you want to run it

    I run the form with this command.
    ReturnValue := UpdatingForm.AccessFunction();

    But i can't run this command because the command wait i close the form "UpdatingForm" to continu if i run my form "Updating Form" with Form.run that's ok i can run some fonction but i don't know how run a fonction when the form "UpdatingForm" close.
  • jjanauskasjjanauskas Member Posts: 49
    I'm not sure if I completely understand your problem, but..

    I think the key here is that your function changes the field which is actually the primary key.

    So, returning to the main form, navision tries to do find('=><') which means to find the record with your old no, and if not found, find the next one in alphabetical order, and if that is not found, then look for prior one.

    So in your case it is normal if you renamed your record and the form finds the next no.

    In your situation I really recommend you to use the solution provided by MTC, use .RUNMODAL for the no change function and after that update the current record to the new number.

    If you desperately want to have not modal window of this no change function, then in this case you can use SingleInstance codeunit as a global variable repository to set and update certain information there. OnClose of your service function you could pass some info to that codeunit and OnActivate of your main form you can process that information from that SingleInstance codeunit. You can search here on forums in order to learn more about these codeunits
  • ArhontisArhontis Member Posts: 667
    Hi,

    All I can see is that you delete the old item and create a new one... Is that correct?!?

    To show the newely created item on the form that you use a get on the Rec variable, like:
      .
      .
      .
    It.INSERT;
    It.GET(It."No.");
    IF Rec.GET(It."No.") THEN ; //add this line
    MESSAGE('L''Article '+CodeItem+' a été renommé '+It."No."); 
    

    And if I may comment, why do you delete the old item? That way you lose the connection of posted documents to that item.

    The Delete function deletes the record of the item without executing the OnDelete trigger of the Item table and so leaves junk in the secondary tables of the Item table, like Item Valuation Cost table in the database.
    Using It.Delete(TRUE) is the appropriate way... But you might get an error message about the existance of recs about that item.

    Maybe you want to make a mass rename of the item instead?? or disable the old item (block) and create a new one...
  • SFZ_GregSFZ_Greg Member Posts: 6
    I want to modify the primary key of the item (Item No.). I can't use MODIFY fonction because i need primary key to modify the item !
  • ArhontisArhontis Member Posts: 667
    Maybe I don't understand you right, your code seems that deletes the old item and creates a new one with a new "No."... Is that what you want?

    What about the Item Ledger Entry that has been posted for the Item that you deleted?

    You want the Item Ledger Entry (and other tables) from the old Item to be visible under the new item?

    The whole functionality is just a "No." changing of an item?
  • SFZ_GregSFZ_Greg Member Posts: 6
    Yes i just want changing "No." of an item
    I do a DELETE and a INSERT because i can't use MODIFY !

    Yes I want all table from the old Item being visible under the new Item.

    thx for your help
  • ArhontisArhontis Member Posts: 667
    Then your code should like:
    It.SETCURRENTKEY("No.");
    It.GET(CodeItem);
    It.RENAME(Codetemp);
    CodeFin := Codetemp;
    //It."No." := Codetemp;
    CaptFin := Descriptemp;
    //It.Description := Descriptemp;
    //It.INSERT;
    //It.GET(It."No.");
    MESSAGE('L''Article '+CodeItem+' a été renommé '+It."No.");
    

    In order to get the new item no. back to your parent form and use it to find the new item, then you just have to make a function on your child form like GetNewItemNo that returns the CodeTemp and in the parent form, after the code that calls the child form to call that routine like:
    CLEAR(frmMyChildItemChangeNo);
    .
    .
    .
    IF frmMyChildItemChangeNo.RUNMODAL=Action::LookupOK THEN BEGIN
      IF Rec.FIND(frmMyChildItemChangeNo.GetNewItemNo) THEN ;
    END;
    
  • ArhontisArhontis Member Posts: 667
    Arhontis wrote:
    Then your code should like:
    It.SETCURRENTKEY("No.");
    It.GET(CodeItem);
    It.RENAME(Codetemp);
    CodeFin := Codetemp;
    //It."No." := Codetemp;
    CaptFin := Descriptemp;
    //It.Description := Descriptemp;
    //It.INSERT;
    //It.GET(It."No.");
    MESSAGE('L''Article '+CodeItem+' a été renommé '+It."No.");
    
    (when you rename, the tables that have a table relation to that Field change also... so the new item will have the old Item Ledger Entried e.t.c.)


    In order to get the new item no. back to your parent form and use it to find the new item, then you just have to make a function on your child form like GetNewItemNo that returns the CodeTemp and in the parent form, after the code that calls the child form to call that routine like:
    CLEAR(frmMyChildItemChangeNo);
    .
    .
    .
    IF frmMyChildItemChangeNo.RUNMODAL=Action::LookupOK THEN BEGIN
      IF Rec.FIND(frmMyChildItemChangeNo.GetNewItemNo) THEN ;
    END;
    
  • SFZ_GregSFZ_Greg Member Posts: 6
    Thank you very much !!!!

    That exactly what i need !!!! i don't see the RENAME fonction i'm really .... :(
  • ArhontisArhontis Member Posts: 667
    Don't worry... Practice makes perfect... Just test everything before you are done...

    By the way, welcome to mibuso... :)
  • Jay2007Jay2007 Member Posts: 50
    MTC wrote:
    It's a bit difficult for me to see what you are actually doing TBH and where you are actually doing it. If you are running the second form in a modal manner, then the basic way to get values out of it (going by the thread title) is that it should have a/some global variable(s) that store what it did or the state it ended up in, and you can put in an access function (interface) to get what that value was:

    UpadatingForm.RUNMODAL; // However you want to run it

    ReturnValue := UpdatingForm.AccessFunction();

    // Do what you want with returned value.

    Hi there,

    In relation to this proposed solution above, which is more relevant to my situation, I have implmented it as above, but cannot get the value to return to parent form for some reason?? Assume the following for explanatory purposes :-

    Parent Form = FormA

    Popup Form = FormB

    When FormB is called, using RUNMODAL statement, FormB updates a global variable on FormB called SelectedItemNo.

    There is also a function on FormB called ReturnItemNo with a return value called rReturnItemNo. This function simply assigns SelectedItemNo to the return variable rReturnItemNo.

    In FormA I then issue following statements :-

    FormB.RUNMODAL();

    ItemNo := FormB.ReturnItemNo();


    Can anybody tell me what am I doing wrong here?? ](*,)


    Thanks,

    Jay
Sign In or Register to comment.