[Nav 2016] Problems with xRec.Status
pjung
Member Posts: 6
Hello,
i want to check if the status has been changed with this code below
But xRec.Status and Rec.Status has always the same value.
Other Fields of this recs are different but not the status?
Is this an issue or do I missunterstand something?
i want to check if the status has been changed with this code below
[EventSubscriber] Warehouse Shipment Header.OnBeforeModify.Event(VAR Rec : Record "Warehouse Shipment Header";VAR xRec : Record "Warehouse Shipment
IF (xRec.Status <> Rec.Status) THEN BEGIN
...
END;
But xRec.Status and Rec.Status has always the same value.
Other Fields of this recs are different but not the status?
Is this an issue or do I missunterstand something?
0
Best Answer
-
Hi, I worked a bit on this and found that by doing an xRec.GET before testing Rec vs xRec it will work.
And you can even trick the system and do it in the OnAfterModify event if you have another event subscriber get the xRec OnBeforeModify and DON'T get it in your OnAfterModify event subscriber.
Try something like this:OnRun() Bin.GET('BLUE','A1'); Bin.Description := FORMAT(CURRENTDATETIME); Bin.MODIFY; LOCAL [EventSubscriber] BinOnBeforeModify(VAR Rec : Record Bin;VAR xRec : Record Bin;RunTrigger : Boolean) xRec.GET(Rec."Location Code",Rec.Code); MESSAGE('xRecBeforeModifyEvent: '+xRec.Description+'\'+'RecBeforeModifyEvent: '+Rec.Description); LOCAL [EventSubscriber] BinOnAfterModify(VAR Rec : Record Bin;VAR xRec : Record Bin;RunTrigger : Boolean) //xRec.GET(Rec."Location Code",Rec.Code); MESSAGE('xRecAfterModifyEvent: '+xRec.Description+'\'+'RecAfterModifyEvent: '+Rec.Description);
5
Answers
-
Hi,
I think that xRec only have the previous values on Pages (or forms).
The events may not have the previous values.
Regards,
parm0 -
I don't thinkos so because other fields (for example User Id) has the previous value0
-
Hi,
Give it a try -
Instead of subscribing OnBeforeModify.Event, try subscribing OnAfterModify.Event.
Before Modify Both values will be same right?
Thanks & Regards,
Saurav Dhyani
Do you Know this About NAV?
Connect - Twitter | Facebook | Google + | YouTube
Follow - Blog | Facebook Page | Google + Page0 -
YesBefore Modify Both values will be same right?
After Modify are the vaules the same, tooInstead of subscribing OnBeforeModify.Event, try subscribing OnAfterModify.Event.0 -
Which NAV 2016 CU are you using?
Thanks & Regards,
Saurav Dhyani
Do you Know this About NAV?
Connect - Twitter | Facebook | Google + | YouTube
Follow - Blog | Facebook Page | Google + Page0 -
Cumulative update 3 for Microsoft Dynamics NAV 20160
-
No one has an idea?0
-
Hi,
a- The Warehouse Shipment Header.OnModify() itself does not modify the Status so OnBeforeModify and OnAfterModify are the same for this field.
b- Could it be the Status changes are never followed by a Modify(TRUE); statement? (Use the Runtrigger)
Good luck.\\The truth exists in seven versions.0 -
a- OnBeforeModify and OnAfterModify have different states, so i think it will be modified.
b- The run trigger doesn't matter my code. Because i want only to check the state and i do not check the run trigger.
So it my code will always run if the event will be triggered.0 -
Hi,
Let me try to explain in different words.
In the Warehouse Shipment Header.OnModify() trigger in the table the Status Field is not changed.
Because there is no code in OnModify that changes the Status Field:
Code in Table 7320:
OnInsert()...
OnModify()
OnDelete()...
Can you find anywhere in NAV where the Status Field is changed followed by an Rec.Modify() statement?
If not, then you cannot test for a Status Field change in the OnBeforeModify or OnAfterModify events.
I hope this explains it better.\\The truth exists in seven versions.0 -
-
Hi, I worked a bit on this and found that by doing an xRec.GET before testing Rec vs xRec it will work.
And you can even trick the system and do it in the OnAfterModify event if you have another event subscriber get the xRec OnBeforeModify and DON'T get it in your OnAfterModify event subscriber.
Try something like this:OnRun() Bin.GET('BLUE','A1'); Bin.Description := FORMAT(CURRENTDATETIME); Bin.MODIFY; LOCAL [EventSubscriber] BinOnBeforeModify(VAR Rec : Record Bin;VAR xRec : Record Bin;RunTrigger : Boolean) xRec.GET(Rec."Location Code",Rec.Code); MESSAGE('xRecBeforeModifyEvent: '+xRec.Description+'\'+'RecBeforeModifyEvent: '+Rec.Description); LOCAL [EventSubscriber] BinOnAfterModify(VAR Rec : Record Bin;VAR xRec : Record Bin;RunTrigger : Boolean) //xRec.GET(Rec."Location Code",Rec.Code); MESSAGE('xRecAfterModifyEvent: '+xRec.Description+'\'+'RecAfterModifyEvent: '+Rec.Description);
5
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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


