Transaction in form triggers

Cem_KaraerCem_Karaer Member Posts: 281
Hi all,

I try to delete all data in my customized table in the OnAfterGetRecord trigger of a form. But Navision does not permit me to do this saying

You cannot make any changes in the database until a transaction has been started.

How can I persuade it?
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005

Answers

  • kinekine Member Posts: 12,562
    It cannot be done in this way, because it is fobidden. Say us what you want to reach and may be that we will help you with solving the problem. Answer for now is:

    You cannot persuade NAV to do it in this way...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Cem_KaraerCem_Karaer Member Posts: 281
    I have an item buffer table that contains inventory values of an item (and its variants) from different companies. I delete this table for every item and populate it again. And the list of that buffer table is on the item card. My customer (not me!) wants to see those figures in this way. Of course the list must be refreshed for every item which the item card shows.
    Because the routine requires deleting and populating a normal table, a transaction begin is required. But the form triggers which will make the refreshment does not begin a transaction.
    Help!
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • kinekine Member Posts: 12,562
    If I understand correctly, you have list of items, and after you select some, you see in subform inventory from other companies for this item?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Cem_KaraerCem_Karaer Member Posts: 281
    I may say yes. I am on one item and some other items are connected to this item via one field (a kind of group field). I get inventory information of this group of items from other companies and show these information on the item card in a subform. Everything works neatier than I may even presume but the problem shows up when this table is needed to be refreshed.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • kinekine Member Posts: 12,562
    Than do not use OnAfterGetRecord but OnAfterGetCurrRecord. You need to refresh the subform just when current selecter record is changed, not each time is some record read from DB... :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Cem_KaraerCem_Karaer Member Posts: 281
    Nop, doesn't work :(. But thank you for your help. I think it will be easier to persuade my customer than Navision :D.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • krikikriki Member, Moderator Posts: 9,110
    You should base your subform on a temptable and create a function in the subform that is called from the mainform.OnAfterGetCurrentRecord. In that function you fill up a temptable that is then shown on the subform. This is possible because writing in a temptable does not create a transaction.
    This is the code you need to use in the subform for running it on a temptable:
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    tmpTempTable.COPY(Rec);
    blnFound := tmpTempTable.FIND(Which);
    Rec := tmpTempTable;
    EXIT(blnFound);
    
    Form - OnNextRecord(Steps : Integer) : Integer
    tmpTempTable.COPY(Rec);
    intResultSteps := tmpTempTable.NEXT(Steps);
    Rec := tmpTempTable;
    EXIT(intResultSteps);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Scott_FrappierScott_Frappier Member Posts: 90
    You could also handle this with the OnTimer trigger...I personally do not like it but if needed and critical to your business process, you could consider it...

    We had to use this in order to make it so that users could copy/paste data from one sales order to another, as it was a requirement. It works wonderfully thus far...let's hope it stays that way :).

    - Scott
    Scott Frappier
    Vice President, Deployment Operations

    Symbiant Technologies, Inc.
    http://www.symbiantsolutions.com
  • Cem_KaraerCem_Karaer Member Posts: 281
    You should base your subform on a temptable
    How can I base a form on a temptable. If I can understand that process, I will be able to solve my problem.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • krikikriki Member, Moderator Posts: 9,110
    cemkaraer wrote:
    You should base your subform on a temptable
    How can I base a form on a temptable. If I can understand that process, I will be able to solve my problem.
    You first create a normal subform on a real table.
    In some triggers (see my previous post), you need to put some code (see my previous post) so it works on a temptable. The only thing you need as extra is to fill up the temptable. For this you need to create a function called by the main form with parameters as to which data you need in the temptable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Cem_KaraerCem_Karaer Member Posts: 281
    That's it Kriki! That is absolutely what I want. Thank you.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
Sign In or Register to comment.