Hi, today I will discuss Web Service with below requirement. You can check other earlier post on this topic using search on right side of this blog page.
I got one request on topic from one of my customer cum blog follower, case study is as follows:
a) Will update Qty to Ship on document using Web Service from other application
b) Update Tracking Line for the Shipment using Web Service from other application
c) Post the Shipment using Web Service from other application
To get this we will create an Extension using VS Code which will have:
a) Codeunit with some functions which will be called using Web Service
b) A XML file to automatically expose above codeunit upon publishing this extension
Let us start how to achieve above requirement:
I have created this in BC16, will be same for other versions too.
Creating a AL Project:
Update your app.json & launch.json as per your environment, authentication, dependencies, port etc.
Creating a Codeunit: (TrackingCodeWS.al)
This function will be used to update “Qty. to Ship” on Sales Line
InitLot function as name suggests.
GetNextEntryNo function as name suggests.
It will depend on how you design your codeunit, you may require or not depends on logic how you use them.
AssignLotSalesLine is function which fills the lot details to temp Reservation Entry Table.
CreateReservationEntrySalesLine is the main function which actually makes your Tracking Lines and assign to Sales Line as per information filled in TempReservationEntry table in above function.
PostSalesOrder function is used for posting your Shipment.
Creating XML file to Publish Web Service
This XML file will ensure publishing of Web Service on Install of the Extension. You can directly make entry to Web Service table but benefit of using XML is when to Uninstall your extension the Web Service too will be removed, else if entry made to table you will have to take care to same yourself.
After Install of Extension, your Web Service is automatically Published.
Consume Web Service from Visual Studio
Below is the C# code to consume Web Service created above, you can modify code as per your requirement.
In above code we added Service Reference to Web Service and called functions created in Codeunit.
You can see earlier posts for step wise instruction how to add Web Reference to the Web Service in Visual Studio.
Here “1” is used for Document Type = Order,”1008″ is my order no, 10000 is the Line No., 2 is the Quantity to Ship.
“L0001” & “L0002” is my Lot No, Serial No. is blank in this case, 1 is the Quantity, last three parameter is same as in above function call.
First 2 Parameter is same as above function call Document Type & Order No, third parameter is Ship = TRUE, Fourth Parameter is Invoice = FALSE.
This post gives you overall Idea how you can use Web Service to handle Sales Document from Web Service, you can make required modification to achieve exactly as per your requirement.
You must be logged in to post a comment.