Hi,
I am looking for some inspiration to creating NAV WebServices, as the documentation and examples I have been able to find doesn’t contain, what I am looking for.
I am working on a new solution where all business logic shall be performed inside NAV and with a .NET based frontend (UI).
I need to have a set of parameters passed from the UI to NAV, have some business logic performed in NAV including collecting data, creating records etc.,
and then based on that, have a set of records exposed to the UI.
As I see it, I can send a list of parameters to a function in a codeunit, and that function can of course carry out all necessary in NAV, but to be able to expose multiple records to the UI, I probably need to use a page.
I can create a function in a page, but parameters passed to that will be lost on the following WS-call to that page.
In other words, how can I through a single WS-call have
- multiple parameters passed to NAV,
- initiated some business logic to be performed in NAV based on these parameters and
- collected and exposed multiple records from NAV as the “response” to the WS-call.
I am not looking for the .NET code to be performed in UI, but the structure and code-placement inside NAV (C/SIDE).
Hope the above makes sense.
Hope anyone have an example or some hints on “how-to”.
0
Answers
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I have made a small example just to asure, that I have got your idea right.
I have a table, an xmlport and a codeunit.
The xmlport:
with a function to set a filter:
and then the "WS"-codeunit
with params, var. and code (function):
First param to be passed to the xmlport, and then the xmlport as second param.
Is that all, that is needed ? :shock:
If so, it is elegant in simplicity.
Thanks again.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
So I can remove the 5 lines of code, I have shown on my CU-function, and just add my business logic to be performed,
and effectively all that is needed is the xmlport as var-parameter on the WS-function.
That is even simpler
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
(probably would have noticed it when I come to the real case )
i just posted the example below of how to create a sales order via webservices and .net. enter sales orders, new customers with credit cards, edit customers, electronic invoices, instant shipping notifications, return authorization lookups with details, blah blah blah.
it even integrates with zendesk (really easy!).
everytime something ships, it updates a zendesk ticket with the summary.
one thing i can tell you is that you're going down a really good coding path! fun stuff!
if you need help with something specific, i'd be happy to help if i can.
'create nav sales order object
Dim navSalesHeader As New SalesHeaderCard
Dim navShipToCard As New nav.Ship_to_Address.Ship_to_Address
Dim navCSO As New EDI.createSalesOrder
With navSalesHeader
.Document_Type = nav.SalesHeaderCard.Document_Type.Order
.Document_TypeSpecified = True
'================================================
'SET CUSTOMER JUNK
'================================================
.Sell_to_Customer_No = poHeader.SoldTo.PartyId
.Bill_to_Customer_No = poHeader.BillTo.PartyId
.Originator_UserID = userName
'================================================
'SET ORDER JUNK
'================================================
.Document_Date = Now.ToString("MM/dd/yyyy")
.Your_Reference = poHeader.BuyerOrderId
.Order_Date = Now.ToString("MM/dd/yyyy")
.Order_DateSpecified = True
'SET MORE PARAMS HERE...
end with
Dim xGen As New XmlGenericOrdering
Try
'=====================================================
docNo = xGen.createSalesOrder(navSalesHeader)
'=====================================================
Catch ex As Exception
Throw
End Try
Public Function createSalesOrder(ByVal salesHeader As SalesHeaderCard) As String
Dim retval As String = ""
Try
Dim service As New SalesHeaderCard_Service
With service
.Url = System.Web.HttpUtility.HtmlEncode(_wsURL & "Page/SalesHeaderCard")
.UseDefaultCredentials = False
.Credentials = _creds
.Create(salesHeader)
retval = salesHeader.No
End With
Return retval
Catch ex As Exception
Throw
End Try
End Function