You can't make any changes in db until a transac...

tompynationtompynation Member Posts: 398
Hi,

i'm receiving the error when i try to execute a method from my subform.

In the onAfterGetCurrRecord i'm calling this method from my subform:

Form - OnAfterGetCurrRecord()CurrForm.GrondstofSUB.FORM.FillFilters(FabricatieID,Fabricatienr);
CurrForm.GrondstofSUB.FORM.FillGrondStofSamenStelling();

The error occurs in the FillGrondStofSamenStelling() method.
This method looks like the following:


FillGrondStofSamenStelling()
lv_PORegel.RESET;
lv_PORegel.SETRANGE(lv_PORegel.FabricatieID,gv_FabricatieID);
lv_PORegel.SETRANGE(lv_PORegel.Fabricatienr,gv_FabricatieNr);
lv_PORegel.SETFILTER(lv_PORegel.Item,'<>%1','');
IF lv_PORegel.FINDSET THEN BEGIN
REPEAT
IF lv_Item.GET(lv_PORegel.Item) THEN BEGIN
IF lv_Item."Item Category Code" <> 'F' THEN BEGIN
lv_POResultSamenstell.RESET;
lv_POResultSamenstell.ID := 0;
lv_POResultSamenstell.FabricatieID := gv_FabricatieID;
lv_POResultSamenstell.Fabricatienr := gv_FabricatieNr;
lv_POResultSamenstell.SamenstellingType := 'G';
lv_POResultSamenstell.Item := lv_Item."No.";
lv_POResultSamenstell.Omschrijving := lv_Item.Description;
lv_POResultSamenstell.Type := lv_Item."Item Category Code";
lv_POResultSamenstell.Hoeveelheid := lv_PORegel.HoeveelheidKG;
lv_POResultSamenstell.INSERT; END
ELSE BEGIN
// Item is Formule en moet verder opgesplitst worden
lv_Recept.RESET;
lv_Recept.SETRANGE(lv_Recept.ReceptCode,lv_Item."No.");
lv_Recept.SETFILTER(lv_Recept.IsActiefRecept,'TRUE');
IF lv_Recept.FINDFIRST THEN BEGIN
REPEAT
FillGrondStofTable(lv_Recept.ID);
UNTIL lv_Recept.NEXT = 0;
END;

END;
END;
UNTIL lv_PORegel.NEXT = 0;
END;

CurrForm.UPDATE(FALSE);


The error occurs as soon as i try to insert the record (see line in bold)

Anyone see why this would happen?

Answers

  • tompynationtompynation Member Posts: 398
    if i try to insert a dummy record, so changing the subform method to this:


    FillGrondStofSamenStelling()
    lv_POResultSamenstell.RESET;
    lv_POResultSamenstell.ID := 0;
    lv_POResultSamenstell.FabricatieID := gv_FabricatieID;
    lv_POResultSamenstell.Fabricatienr := gv_FabricatieNr;
    lv_POResultSamenstell.SamenstellingType := 'G';
    lv_POResultSamenstell.Item := '1021';
    lv_POResultSamenstell.Omschrijving := 'Test';
    lv_POResultSamenstell.Type := 'G';
    lv_POResultSamenstell.Hoeveelheid := 1;
    lv_POResultSamenstell.INSERT;

    It also generates the error
  • kinekine Member Posts: 12,562
    OnfterGetCurrRecord trigger is not good trigger for changing anything in the database. It is why you have this error. This trigger does not allow it. What do you want to do? There must be better way than using OnAfterGetCurrRecord trigger...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    If you browse through a record (OnAfterGetCurrRecord / OnAfterGetRecord) you will insert a new record in a other table, why this :?:

    Why not if you insert / modify a reord on your base table, then insert / modify the record(s) in your sub table.

    So i ask you, what do you want to do :?:
    Give us some more infos and we will find the best solution for you :)

    regards
    Do you make it right, it works too!
  • tompynationtompynation Member Posts: 398
    all i want to do is fill up a table for each record...

    And then display this table in the subform.
  • kinekine Member Posts: 12,562
    There is one main question - why you are generating the data "on fly", why they are not already created in the table and why you don't just filter this table for correct records. This is the NAV way...

    It means, make sure, that you generates all records before you open the form and than just filter for the correct one. If you will generate the records each time someone move the cursor, it will not be usable...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • tompynationtompynation Member Posts: 398
    allright, i changed the way the creations works so the problem is now gone.
Sign In or Register to comment.