Problem with code in onInsert trigger when using webservices

andreaskeller
Member Posts: 11
Hello Everybody
I have a project using Nav 2009 R2 where I expose a page as webservice. Everything works fine, the data can be inserted or updated.
Then I wanted to run some code in the onInsert trigger of the corresponding table. This code works fine when inserting through the classic Nav Client. When the code is triggered from the webservice the code doesn't funtion. When debugging the cs file of the table in Visual Studio I see that the code is processed, but I observed that not every field of the current record (the one to be inserted) is available. It seems as only the primary fields are available. The odd thing is that it still inserts the record correctly.
When I put this code in the onModify trigger of the table and in my c# code using the webservice I put an Update command after the Create command using the same object without modifying it, it works.
Has anybody observed something similar? Thanks for the feedback
Regards, Andreas
I have a project using Nav 2009 R2 where I expose a page as webservice. Everything works fine, the data can be inserted or updated.
Then I wanted to run some code in the onInsert trigger of the corresponding table. This code works fine when inserting through the classic Nav Client. When the code is triggered from the webservice the code doesn't funtion. When debugging the cs file of the table in Visual Studio I see that the code is processed, but I observed that not every field of the current record (the one to be inserted) is available. It seems as only the primary fields are available. The odd thing is that it still inserts the record correctly.
When I put this code in the onModify trigger of the table and in my c# code using the webservice I put an Update command after the Create command using the same object without modifying it, it works.
Has anybody observed something similar? Thanks for the feedback
Regards, Andreas
0
Comments
-
I assume that the webservice is working in similar way as user entering the values manually. The primary key is filled in as first and than insert is called. Than all other fields are validated and modify is called.0
-
I can confirm the assumption from kine. Pages that are used as web services work the normal as they do in the RTC. That is: insert a record after leaving the primary field.
You can read more on this topic here: http://blogs.msdn.com/b/freddyk/archive ... d-rtm.aspx
Quote from this post:Just to recap a couple of facts about Page based Web Services – we are using the pages and the code on the pages to work with sales orders, this means that we need to mimic the way the RoleTailored Client works, and the RoleTailored Client doesn’t create the order header and all the lines in one go before writing anything to the database. Instead what really happens is that once you leave the primary key field (the Order No) it creates the Order Header in the table. The same with the lines, they are created and then you type data into them, after which they are updated.
This does not mean that de web service is doing the insert and update for you. You need to first call the Create method. This will return a reference to the inserted record (with the field Key filled in). Than you can use this variable to specify the other values and call Update function.var service = new Customer_Service(); service.UseDefaultCredentials = true; var myCust = new Customer(); service.Create(ref myCust); myCust.Name = "My Name"; service.Update(ref myCust);
A good programmer makes al the right mistakes
My blog0 -
Thanks for the replies. The execution of the code in the triggers makes more sense now. But to my knowledge you don't always have to call create first with the primary fields and then update the other fields. When you us FieldSpecified = true for non string fields a single create inserts the values into the database, just as it seems for code on triggers an update is necessary.0
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