Hi developers, I am stuck on a problem, maybe you can help me?
I added a table, employment history.
When Employee status is changed, an entry is made in this table.
When an entry is made in employment history, it checks to see if
"Employment Date" "Inactive Date" or "Termination Date" needs to be updated for that employee.
By using the debugger I see that it is executing all the statements, and the employee Employment Date is correctly being set. But when I go back to card there is no change.
I have tried Modify TRUE and FALSE.
I don't want to move the code to the Employee table in case the Employment History is updated not from the employee card.
Any suggestions? Appreciate the feedback always trying to learn...
IF sEmployee.GET("Employee No.") THEN
BEGIN
CASE Action OF
Action::Hire:
BEGIN
mEmployee.GET("Employee No.");
mEmployee."Employment Date" := Date;
mEmployee.MODIFY(TRUE);
END;
END;
Answers
I suggest that you test the return value of the MODIFY i.e.
Also I would test on the GET to avoid run-time errors.
A possibility is that the mEmployee variable is set as a Temporary table
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
They are not temporary tables, but they are local variables.
Is there code later on modifing the record, if so without another GET it would have the old Employment Date and reset it unintentionally
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
onValidate on Status trigger:
But the MODIFY is before... but if I comment it out it works (dates are updated correctly)
OK, so then the question is how do I fix this? It would not let me COMMIT after the MODIFY in the onValidate Status trigger?
By the way... why are you using two different variables for the same record?
RIS Plus, LLC
MVP - Business Apps
Yes I think you've cracked it but the code given is on the table and the CurrForm.UPDATE; will update the form with the current value of Rec. I think the solution is to add code in the onaftervalidate trigger on the status on the form to get the record for the database again and then do the UPDATE
i.e.
GET( "No." );
currform.update( FALSE ); // Update with current Rec and don't save the old values
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
The only reason I have two variables is because I wanted to test the very remote chance that this was causing the problem... (so one for search, one for modification)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
RIS Plus, LLC
MVP - Business Apps
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
For example, I could reverse the logic. First Insert into employment history, then do something like which would also be a good solution. Maybe cleaner even. But then this logic would have to be repeated anytime you modify the History table, so to avoid that I figured it would make more sense the other way around, and all you have to worry about is keeping the history up to date. Also if history is edited directly, Employee records stay up to date as well. Turned out to not be so simple! Like I said at the top, always trying to learn, best case scenario my question (and your help) actually leads to a better understanding of the code for me, so it is appreciated.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I agree but if you look at this example the date is changing as a result of changing the status instead of the history so putting the code in the OnInsert/OnModify of the history table will still give the same result/error. The question is - does the history get changed at all and/or from other sources? If not then the date should be changed from the Onvalidate of the Status on the table.
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
RIS Plus, LLC
MVP - Business Apps
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
RIS Plus, LLC
MVP - Business Apps