Update page when changing record

dabba23dabba23 Member Posts: 77
edited 2015-06-04 in NAV Three Tier
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

Comments

  • Rob_HansenRob_Hansen Member Posts: 296
    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_HansenRob_Hansen Member Posts: 296
    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).
  • dabba23dabba23 Member Posts: 77
    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
    Ann
  • Rob_HansenRob_Hansen Member Posts: 296
    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?"
Sign In or Register to comment.