API Page-OnInsertRecord(BelowxRec: Boolean): Boolean

IvonaK
Member Posts: 115
Hi all,
I have created a new custom API page, and I have seen in a book and in the standart API pages that
exit(false) is used in OnInsertRecord(BelowxRec: Boolean): Boolean on API pages.

Could you please tell me why is like that. In which cases I have to use exit(false) ?
Thanks
Ivona
I have created a new custom API page, and I have seen in a book and in the standart API pages that
exit(false) is used in OnInsertRecord(BelowxRec: Boolean): Boolean on API pages.

Could you please tell me why is like that. In which cases I have to use exit(false) ?
Thanks
Ivona
0
Answers
-
You have to return FALSE if you have inserted the record yourself in code, or if you don't want the record to get inserted at all.
The return value behaves the same for all 3 database related triggers (i.e. the ones shown above).
Microsoft's documentation on this is completely wrong. Here is, what the documentation for NAV 5.0 had to say (This was for a Form, not a Page, but it is still the same.)OnInsertRecord
The C/AL code in this trigger is executed before the system inserts a new record into the table.
[Ok]:= OnInsertRecord
Ok
Data type: boolean
This return value tells the system whether it should insert the record. The system checks the return value after each function call.If Ok is... The system will... TRUE Insert the record (default) FALSE Not insert the record
Even back then, the documentation for the BelowxRec parameter was wrong, as it still is, and even missing from the function's signature as given in the documentation. But, at least, the effect of the return value is described correctly here.
0 -
Hi,
thanks for the feedback, but just as Info:
when I removed the exit(false) from OnInsertRecord(BelowxRec: Boolean) on API page, I was not even able to insert a new record from the postman.
I was getting the following error message:
Regards0 -
Well, yes, if any code executed before the exit inserts the record, you must return false, or you will get the error you got.
As the documentation says:
- the default return value is true
- if you return true, the system will insert the record
It is standard behavior that you (or the system in this case) get the error "The record ... already exists" if you try to insert a record with a primary key that already exists in the database, which is true as soon as you INSERTed the record.1 -
Hi,
Thanks a lot. I got your point now
Have a nice weekend0
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