Modify record from the OnAfterGetRecord trigger

Solmyr
Member Posts: 51
Hallo All!
exuse for my English, it's not so good but I try to explain the problem in the understandable way
I added new boolean field on the table 37 sales line. This field shows is the cost adjusted for line item or not. It's not the standard NAV cost adjustments, it is additional functionality which determines the value of this field through few different tables (Item, Sales Shipment Line, Item Ledger Entry, Item Application Entry). It is the reason why I can't make this field as a simple FlowField. Purpose of this field is possibility to filter sales order (subform) and see which lines are adjusted and which aren't. The problem is that the new field should be updated each time I run the sales order.
If I call my function (which updates this field for current line) from sales order subform - OnAfterGetRecord trigger and function does not modify sales line - the value of new field is showed correctly on the form but still equal to old value in the table. So the filtering is not possible because table is not modified with new values.
If the function tries to modify sales line the standard trigger error appears ("you cannot make any changes to the database in this trigger").
Now I don't see any solution...
The only way is add the new button to call this function manually and update the subform. But it's inconveniently for my needs.
Navision version: 3.7 NA
Thanks In advance
exuse for my English, it's not so good but I try to explain the problem in the understandable way
I added new boolean field on the table 37 sales line. This field shows is the cost adjusted for line item or not. It's not the standard NAV cost adjustments, it is additional functionality which determines the value of this field through few different tables (Item, Sales Shipment Line, Item Ledger Entry, Item Application Entry). It is the reason why I can't make this field as a simple FlowField. Purpose of this field is possibility to filter sales order (subform) and see which lines are adjusted and which aren't. The problem is that the new field should be updated each time I run the sales order.
If I call my function (which updates this field for current line) from sales order subform - OnAfterGetRecord trigger and function does not modify sales line - the value of new field is showed correctly on the form but still equal to old value in the table. So the filtering is not possible because table is not modified with new values.
If the function tries to modify sales line the standard trigger error appears ("you cannot make any changes to the database in this trigger").
Now I don't see any solution...
The only way is add the new button to call this function manually and update the subform. But it's inconveniently for my needs.
Navision version: 3.7 NA
Thanks In advance

Oleg Dovgalenko
0
Comments
-
Maybe I named the topic in a wrong way. Actually I know that we can't modify a record from the OnAfterGetRecord. But probably there are some solutions to my problem to avoid modification from that trigger...Oleg Dovgalenko0
-
the value of new field is showed correctly on the form but still equal to old value in the table.
Maybe it's me but I don't know what this means.
In your function are you specifing the Doc Type Doc No & Line No so it knows which one to update?
What's the code?0 -
I'll try to explain
the function is called from sales order subform, OnAfterGetRecord triggerShowShortcutDimCode(ShortcutDimCode); SetCostAdjustment; // this one
Function SetCostAdjustmentIF (Type = Type::Item) AND ("No." <> '') THEN BEGIN Item.RESET; IF Item.GET("No.") THEN BEGIN "Cost Adjusted" := TRUE; CASE "Document Type" OF "Document Type"::Order: BEGIN SalesShptLine.SETCURRENTKEY("Order No.","Order Line No."); SalesShptLine.SETRANGE("Order No.","Document No."); SalesShptLine.SETRANGE("Order Line No.","Line No."); END; "Document Type"::Invoice: BEGIN SalesShptLine.SETRANGE("Document No.","Shipment No."); SalesShptLine.SETRANGE("Line No.","Shipment Line No."); END; END; SalesShptLine.SETFILTER("Qty. Shipped Not Invoiced",'<>0'); IF SalesShptLine.FIND('-') THEN IF (SalesShptLine.Type = SalesShptLine.Type::Item) AND (SalesShptLine."Item Shpt. Entry No." <> 0) THEN BEGIN ItemLedgEntry.GET(SalesShptLine."Item Shpt. Entry No."); ItemAppEntry.SETCURRENTKEY("Item Ledger Entry No.", "Outbound Item Entry No."); ItemAppEntry.SETRANGE("Item Ledger Entry No.",ItemLedgEntry."Entry No."); ItemAppEntry.SETRANGE("Outbound Item Entry No.",ItemLedgEntry."Entry No."); IF ItemAppEntry.FIND('-') THEN BEGIN REPEAT ItemLedgEntry2.RESET; ItemLedgEntry2.GET(ItemAppEntry."Inbound Item Entry No."); IF NOT ItemLedgEntry2."Completely Invoiced" THEN "Cost Adjusted" := FALSE; UNTIL ItemAppEntry.NEXT = 0; END; END; END; END;
it works with the rec of subform so I don't need to specify Doc Type, Doc No & Line No
as you can see there is no MODIFY expression
after opening sales order I have the set of records on the subform where Cost Adjusted is calculated right.
but, if I find these records in the table 37 the Cost Adjusted field will be set to No. in all of them
and I can't filter sales lines by this field because it isn't filled in table
if I place MODIFY into my function the trigger error ("you cannot make any changes to the database in this trigger") appearsOleg Dovgalenko0 -
Solmyr wrote:I'll try to explain
the function is called from sales order subform, OnAfterGetRecord triggerShowShortcutDimCode(ShortcutDimCode); SetCostAdjustment; // this one
Function SetCostAdjustmentIF (Type = Type::Item) AND ("No." <> '') THEN BEGIN Item.RESET; IF Item.GET("No.") THEN BEGIN "Cost Adjusted" := TRUE; CASE "Document Type" OF "Document Type"::Order: BEGIN SalesShptLine.SETCURRENTKEY("Order No.","Order Line No."); SalesShptLine.SETRANGE("Order No.","Document No."); SalesShptLine.SETRANGE("Order Line No.","Line No."); END; "Document Type"::Invoice: BEGIN SalesShptLine.SETRANGE("Document No.","Shipment No."); SalesShptLine.SETRANGE("Line No.","Shipment Line No."); END; END; SalesShptLine.SETFILTER("Qty. Shipped Not Invoiced",'<>0'); IF SalesShptLine.FIND('-') THEN IF (SalesShptLine.Type = SalesShptLine.Type::Item) AND (SalesShptLine."Item Shpt. Entry No." <> 0) THEN BEGIN ItemLedgEntry.GET(SalesShptLine."Item Shpt. Entry No."); ItemAppEntry.SETCURRENTKEY("Item Ledger Entry No.", "Outbound Item Entry No."); ItemAppEntry.SETRANGE("Item Ledger Entry No.",ItemLedgEntry."Entry No."); ItemAppEntry.SETRANGE("Outbound Item Entry No.",ItemLedgEntry."Entry No."); IF ItemAppEntry.FIND('-') THEN BEGIN REPEAT ItemLedgEntry2.RESET; ItemLedgEntry2.GET(ItemAppEntry."Inbound Item Entry No."); IF NOT ItemLedgEntry2."Completely Invoiced" THEN "Cost Adjusted" := FALSE; UNTIL ItemAppEntry.NEXT = 0; END; END; END; END;
it works with the rec of subform so I don't need to specify Doc Type, Doc No & Line No
as you can see there is no MODIFY expression
after opening sales order I have the set of records on the subform where Cost Adjusted is calculated right.
but, if I find these records in the table 37 the Cost Adjusted field will be set to No. in all of them
and I can't filter sales lines by this field because it isn't filled in table
if I place MODIFY into my function the trigger error ("you cannot make any changes to the database in this trigger") appears
Hi
Add a menu option "Update Adjusted Cost" on "Function" button.
I think it isn't another solution.
MatteoReno Sistemi Navision Developer0 -
Eto wrote:Hi
Add a menu option "Update Adjusted Cost" on "Function" button.
I think it isn't another solution.
Matteo
but as I wrote in my first message adding a button/menu button is inconveniently. It's possible and easy way but it sholud be updated automatically...Oleg Dovgalenko0 -
Well I guess that why there's a function buttonthe new field should be updated each time I run the sales order.0
-
Hi,
solution I often use is:
in OnAfterGetRecord put statement
SAVERECORD;
and calling your code put in ONMODIFY trigger.0 -
lubost wrote:Hi,
solution I often use is:
in OnAfterGetRecord put statement
SAVERECORD;
and calling your code put in ONMODIFY trigger.
Hi, I tried this solution. When I opened sales order the confirmation message appeared:
Do you want to rename the rocord?
If I pressed Yes - I saw the error message:
You cannot rename a Sales Header.Oleg Dovgalenko0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions