Update page when changing record

dabba23
Member Posts: 77
Hi,
I have to update Posting Date with TODAY on Sales Order every time I change record.
I have added following code on OnAfterGetRecord:
lr_SH.GET("Document Type","No.");
IF lr_SH."Posting Date" <> TODAY THEN BEGIN
lr_SH."Posting Date" := TODAY;
lr_SH.MODIFY(FALSE);
END;
If I use MODIFY I get following error message:
"A transaction must be started before changes can be made to the database"
If I don't use MODIFY then nothing happens, even with CurrPage.UPDATE(FALSE);
So how can I change Posting Date on every Sales Order I pass through?
Regards
Ann
I have to update Posting Date with TODAY on Sales Order every time I change record.
I have added following code on OnAfterGetRecord:
lr_SH.GET("Document Type","No.");
IF lr_SH."Posting Date" <> TODAY THEN BEGIN
lr_SH."Posting Date" := TODAY;
lr_SH.MODIFY(FALSE);
END;
If I use MODIFY I get following error message:
"A transaction must be started before changes can be made to the database"
If I don't use MODIFY then nothing happens, even with CurrPage.UPDATE(FALSE);
So how can I change Posting Date on every Sales Order I pass through?
Regards
Ann
0
Comments
-
I'm tempted to ask a bit more about what you're trying to accomplish here, but anyway...
Assuming this is on the Sales Order page (or form if you're on an older version), try just changing the code to:IF "Posting Date" <> TODAY THEN "Posting Date" := TODAY;
Right now you're using a record variable to get a different instance of the record (not Rec being used on the page/form). So, if you don't MODIFY it, nothing happens. The above approach should change the field value on the current rec so you can carry on from there.Rob Hansen
http://www.epimatic.com0 -
I shouldn't have replied so quickly. Also be careful here...you're directly setting the field value without a VALIDATE. A change to the posting date triggers other logic, especially for foreign currency documents (to update exchange rates). So, make sure you do in fact want to bypass all of that (which I would not advise).Rob Hansen
http://www.epimatic.com0 -
Rob Hansen wrote:I'm tempted to ask a bit more about what you're trying to accomplish here, but anyway...
Assuming this is on the Sales Order page (or form if you're on an older version), try just changing the code to:IF "Posting Date" <> TODAY THEN "Posting Date" := TODAY;
Right now you're using a record variable to get a different instance of the record (not Rec being used on the page/form). So, if you don't MODIFY it, nothing happens. The above approach should change the field value on the current rec so you can carry on from there.
Hi Rob,
The thing is, which I didn't write, that I have also tried what you suggest. I have also tried to call a Function from T36, but no matter what, I get the same Transaction Error.
The interesting part is, when I leave a Message("No."), I get the next Sales Order number, when pressing Next.
But if I debug through my code, the Message("No.") is the number of the record, I want to leave.
Regards
Ann0 -
I think you need to look at another approach here. Are you looking to ensure that the document is posted using today's date? If so, i'd add the logic to the post actions. If the user needs the ability to override it in some cases, you can make it a CONFIRM prompt if posting date <> today. i.e. "Do you want to set the posting date to today?"Rob Hansen
http://www.epimatic.com0
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