web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Error when sending email with Report attachment from OnValidate of a field

(0) ShareShare
ReportReport
Posted on by 5,136

Help! I am running into an error when attaching a report in an SMTP mail.  Usually, I get no error if I call the SMTP mail via Job queue and attach a report.  So codewise, there's nothing wrong with my email codeunit with report attachment.  The problem occurs when I call this codeunit from the ONVALIDATE event of the Requested Receipt Date field in the Purchase Order Card.  Note that the source for the Purchase Order Card is Purchase Header.  The source for the PO Report I am attaching is also Purchase Header.  When I attach the PO Report in the email,  I DO get the email with report attachment no problem.  But since I am calling this code unit from ON VALIDATE event, I get an error "An attempt was made to change an old version of a Purchase HEader record.  The record should first be reread from the database.  THis is a pogramming error.  Identification fields and values: Document Type='Order', No.='2223'".   I need to use the ONValidate method of Requested Receipt or OnModifyRecord because I need to access the rec and xrec to email users of before and after value of mod.

 Like I said earlier, the email gets sent with the PO Report attachment.  The problem is on the PO Card, it complains with above error message.

Any ideas on how I could fix this?  I am thinking maybe the error is because the current record in PO Card needs to be saved? 

*This post is locked for comments

I have the same question (0)
  • mmv Profile Picture
    11,471 on at

    Hi,

    Please check whether you are modifying the Purchase Header table.  If so, you need to have a COMMIT statement before you could proceed.

    Best Regards,

    MMV

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    As MMV said, before u call the any other method call COMMIT. It will register your modifications and will give you the latest version of data.

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    I don't recommend COMMIT statement, rather use a get statement in your codeunit before you modify the record.

  • Suggested answer
    Jan Veenendaal Profile Picture
    510 on at

    How do you pass the Rec and xRec to the report? I guess since the report will (based on the applied filters) loop through Rec that will be the cause of the error.

    I would suggest to create a new record variable of type "Purchase Header", copy the contents of Rec into that record (use COPY or TRANSFERFIELDS or any other method you like), and pass that new variable to the report.

  • Suggested answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi mbr,

    Did you try "CurrPage.UPDATE;" in "Requested Receipt Date - OnValide" trigger of page? It is not recommended to use COMMIT statement in OnValidate Triggers of Table Fields, it can make data inconsistent especially when posting progress passes the COMMIT statement and raises an error.

  • Verified answer
    mbr Profile Picture
    5,136 on at

    HI All,

    I decided to just move the call to send email with PO report attachment on the ONclose event of the page.  This way, I don't have to deal with the COMMITS.  I tried making the commit work but it caused problems for the page.  Thank you all for your help!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans