Error Updating 'Requested Delivery Date' Field Automatically Upon Item Insertion in New Record

isabtogumonisabtogumon Member Posts: 47
Hello,

After inserting the item I want to automatically update the 'Requested Delivery Date' field (it is a new record), however, the field value shows empty in the record.

It is worth mentioning that while debugging the code, I entered the filter of the line 'if SalesLine.FindFirst() then begin':
4tecb47lsya1.png

In addition to that, when changing the registry this error is shown:
gm0so391osna.png


Any reason for what's happening?

Best Answer

  • vaprogvaprog Member Posts: 1,140
    Answer ✓
    • The shown error messages are not caused by the given code (at least not directly. Messing with filters may possibly cause this error elsewhere).
    • You should use a different trigger. I would probably use some trigger related to validating the "No." field.
    • You should use Get to fetch a record by it's primary key, not a combination of SetRange and FindFirst.
    • You must not modify the filter on records passed as Var parameter lightly. Rec.Reset() above likely causes a mess.
    • You should not get the Sales Header yourself here. Use Rec.GetSalesHeader instead.
    • You should not Modify() SalesLine in this way, here. You should work with Rec instead. (Not modify it's Position, but making sure your changes are passed back to the caller in the Var parameter. You do not need to get the sales line from the database at all. You should use the Rec passed in.
    • Item."Lead Time Calculation" is a DateFormula. CalcDate expects a DateFormula. Pass it on without messing with it like you do.
    • A DateFormula formatted as string, surrounded by angle brackets uses US form for terms of the date formula. Format uses localized forms. Building a date formula string like you do here is asking for trouble. Just use Format, if some function actually expects a date formula as string and you only have a value of type DateFormula. Use the form with angle brackets only as a literal in code, and wherever you need to store a date formula as text. Use the DateFormula type to store a date formula in the database.
    • Always use Validate() and Modify(True) unless you know for sure that not using the trigger does not bypass any code that should run and running the trigger would cause problems elsewhere (e.g. validation loops).

Answers

  • vaprogvaprog Member Posts: 1,140
    Answer ✓
    • The shown error messages are not caused by the given code (at least not directly. Messing with filters may possibly cause this error elsewhere).
    • You should use a different trigger. I would probably use some trigger related to validating the "No." field.
    • You should use Get to fetch a record by it's primary key, not a combination of SetRange and FindFirst.
    • You must not modify the filter on records passed as Var parameter lightly. Rec.Reset() above likely causes a mess.
    • You should not get the Sales Header yourself here. Use Rec.GetSalesHeader instead.
    • You should not Modify() SalesLine in this way, here. You should work with Rec instead. (Not modify it's Position, but making sure your changes are passed back to the caller in the Var parameter. You do not need to get the sales line from the database at all. You should use the Rec passed in.
    • Item."Lead Time Calculation" is a DateFormula. CalcDate expects a DateFormula. Pass it on without messing with it like you do.
    • A DateFormula formatted as string, surrounded by angle brackets uses US form for terms of the date formula. Format uses localized forms. Building a date formula string like you do here is asking for trouble. Just use Format, if some function actually expects a date formula as string and you only have a value of type DateFormula. Use the form with angle brackets only as a literal in code, and wherever you need to store a date formula as text. Use the DateFormula type to store a date formula in the database.
    • Always use Validate() and Modify(True) unless you know for sure that not using the trigger does not bypass any code that should run and running the trigger would cause problems elsewhere (e.g. validation loops).
Sign In or Register to comment.