Click here to Skip to main content
15,880,469 members
Articles / Desktop Programming / Windows Forms

Authorize Navision Sales Order Line with Navision add-on "NDA", Developed in C#

Rate me:
Please Sign up or sign in to vote.
3.73/5 (7 votes)
29 Dec 2010CPOL14 min read 56.7K   2K   6   12
This is an excellent example of how to integrate Navision with any third party application with data flowing in and out from Navision to that application.

Introduction

This article demonstrates how a business process which is running outside Navision ERP can be easily integrate with any of the business processes in Navision. To understand this better, I had used a real time scenario.

Consider a system developed in C# which is having functionality to authorize the Sales Orders Qty. Once the Sales Order is being created in Navision, than from C#, one can do various operations from this article:

  1. View the Sales Order from C#
  2. Authorize the Sales Order qty from C#. This not only authorizes the sales line qty from C# but also runs the business logic residing in Navision while authorizing the Sales order.
  3. After authorizing, one can post the Sales Order from C# for Sales Shipment.
  4. After Sales Shipment, one can also post the Sales order to Sales Invoice.
  5. One can also post the Sales order to Sales Shipment and Sales Invoice simultaneously.
  6. This article not only allows to authorize the Sales order but also update for how much qty it is authorized for. This means that user cannot make shipments and invoices more than authorized qty.
  7. User cannot post the Sales Order till it is authorized by C#
  8. After posting authorized Navision SO line Items one can see the posted shipments and invoice from this “Navision Document Authorization” Add-on.

Now the intelligent people will definitely ask why we are doing sales authorization from C#, rather than doing this, why we cannot customize in Navision only?

To understand this, consider one scenario, i.e.:

Client or ISV has an authorizing application which has all business logics to authorize the Sales order qty and now client or ISV asked to integrate this functionality with Navision so that we can leverage the functionalities of Authorization application to Navision and vice versa.

We will get the following benefits by using this kind of integration:

  1. If the functionality is already there in one add-on so no need to develop from scratch in Navision and just integrate it with Navision within 8 hrs time.
  2. As the add-on functionality can be developed in .NET platform and easily be integrated with Navision 2009 Sp1 thus it will save lot of ISV’s time to release the add-on product in the market for Navision.
  3. Rather than investing time on developing functionality which is present in add-on, ISVs can be used during that time to add some more features to their Add-on as this will give more added values to their add-on and give a more competitive edge to their rivals.

Consider that client had given us API which is returning the Sales Order numbers, Line numbers, authorize information and authorize qty. Now by using these 5 fields, I had developed a connector or adapter which updates the Navision Sales Order through C# and also performed all operations which are defined from step a to h.

This article is developed to help ISVs, clients and developers to integrate their legacy applications with Microsoft Dynamics Navision.

Some questions might arise in the audience's mind that what kind of applications can be integrated by using the framework that I defined in this article, so please find the answers here only, i.e.:

  1. Any kind of retail application developed in VB, C# can be easily integrated with Navision business process. So there is no need to develop retail system in Navision if already available as third party application. Just integrate it with Navision application by using the framework in this article.
  2. Any kind of Document tagging applications and authorization applications can be easily integrated with SOP process, POP process, Manufacturing processes and all other processes in Navision.
  3. Export and Import functionality developed in C#, WPF can be easily integrated with Navision.
  4. Quality Module developed in C#, WPF can be easily integrated with Navision processes.
  5. Batch manufacturing, Agile manufacturing, Lean manufacturing … developed in C#, WPF… can be easily integrated with Navision processes.

Above, I had given some of the Add-On examples developed in C# and WPF that can be easily integrated with Navision. So it's all easy for ISVs to integrate their applications with Navision without knowing Navision proprietary language CAL. This is interesting. I had worked in various ISVs for Navision. We used to develop connector by using COM in CAL and to place code in lot of forms which we want to integrate but now by using the architecture defined in this article, one need not place buttons on Navision forms but only to take the whole data for Navision table through WCF in C# application and integrate it. It allows not only passing data from Navision to outside world but also to perform the business logic in Navision from outside and also posting back the processed data from outside world back to Navision.

We had talked a lot about all interesting things above, now start a wonderful exciting journey of C# coding to integrate Navision with Document authorization…

Background

As this is an Add-on, hence some modifications will be required at Navision side like adding some fields in tables, pages and exposing pages and codeunit as web service. After exposing Navision objects as web service, we can start our development in C#. Navision proprietary language is CAL and IDE for Navision is Object designer. Tables, Forms, Pages, Codeunits, Dataports, Menusuites and XmlPort are the Objects of Navision. In brief, Pages and forms are used to display table data to end user. Codeunit are like SQL procedure. Dataport and XMLport are used to export and import data from and to Navision. In Navision, we can expose page and codeunit as a webservice. Codeunits and page enables the business logic and data of Navision to outside world. I had used Navision 2009 sp1, .NET 3.5, VS 2008 sp1 and SQL Server 2005 for this article.

Now start our development in Navision first. (Navision modification will be very less. 98% development will be done in C#.)

Development 1: Adding New Fields in “SalesLine” Tables in Navision

As we are doing Sales Order Item authorization, therefore we have to do modification in SalesLine table, i.e.:

p1.JPG

In the above picture, Added two fields “Authorize” and “Authorize Qty” for ID’s 50000 and 50001.

Development 2: Adding Validation on Two Fields of “SalesLine” Table in Navision

p2.JPG

In the above picture, the following modifications are being done on Navision “SalesLine” table:

C#
//(i)"Qty. to Invoice" field- OnValidate trigger -
// Authorization (The Great AP) Start 
IF ( Authorize = FALSE) THEN 
ERROR(APText002) 
ELSE 
IF ((("Qty. to Invoice") + ("Quantity Invoiced")) > "Authorize Qty") THEN 
ERROR(APText003,"Qty. to Invoice","Authorize Qty"); 
// Authorization (The Great AP) end

The above code specifies that value of "Qty. to Invoice" field cannot be greater then "Authorize Qty"). Here, value of "Authorize Qty" field will come from C# application. This is the integration point of any document authorization management system for Sales cycle.

C#
//(ii) "Qty. to Ship" field- OnValidate trigger – 
//Qty. to Ship - OnValidate() 
// Authorization (The Great AP) Start 
IF ( Authorize = FALSE) THEN 
ERROR(APText002) 
ELSE 
IF ((("Qty. to Ship") + ("Quantity Shipped")) > "Authorize Qty") THEN 
ERROR(APText001,"Qty. to Ship","Authorize Qty"); 
// Authorization (The Great AP) end

The above code specifies that value of "Qty. to Invoice" field cannot be greater then "Authorize Qty"). Here, value of "Authorize Qty" field will come from C# application. This is the integration point of any document authorization management system for Sales cycle.

In the above picture, the highlighted code specifies that before posting of Sales Order to Sales Shipment and Sales Invoice will do the validation check that fields “Qty. to Ship” and “Qty. to Invoice” cannot be greater the “Authorize Qty” field.

Development 3: Creating Codeunit 50001 in Navision

This codeunit is required so that we can post the Sales Order in Navision from C#.

p3.JPG

The above code is exposed as a web service later in this article to enable the C# to do posting.

Development 4: Exposing Page and Codeunit as a Service in Navision

We had developed basic business logic in Navision for Authorization Addon. Now we will call start our C# coding from this point. To start with, first of all, expose the modified Page and Codeunit as a webservice as shown below:

p4.JPG

In the above picture, Form “Web Services” contain records for Pages and Codeunit. This means, pages ID 132, 130, 48, 46, 42, 46 and Codeunit 50001 are exposed as webservice.

Development 5: Creating the C# Application for Document Authorization

Create the “NavisionDocumentAuthorization” Project in C# and give the reference for exposed objects of Navision as shown below:

p5.JPG

In the above picture, addresses for web services are as under, which were exposed on Modification 4.

Development 6: Creating the “FetchNavisionSOP” Class in C#

C#
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using NavisionDocumentAuthorization.SalesHeader; 
using System.Reflection; 
namespace NavisionDocumentAuthorization 
{ 
	class FetchNavisionSOP 
	{ 
	SalesHeader_Binding sh_serv =new SalesHeader_Binding(); 
	SalesHeader.SalesHeader sh = 
		new NavisionDocumentAuthorization.SalesHeader.SalesHeader(); 
	SalesLine_Binding navSL = new SalesLine_Binding(); 
	SalesLine_Filter salesLineFIlterNo = new SalesLine_Filter(); 
	SalesLine_Filter salesLineFIlterType = new SalesLine_Filter(); 
	Sales_Order_Line sline = new Sales_Order_Line(); 
	SalesHeader.SalesHeader sr = 
		new NavisionDocumentAuthorization.SalesHeader.SalesHeader(); 
	SalesHeader.SalesHeader[] salesHeader; 
	SO.SalesOrder_Service soos = 
		new NavisionDocumentAuthorization.SO.SalesOrder_Service(); 
	SO.SalesOrder so1; 
	PostedSalesShipment.PostedSalesShipment_Service posSalesShpmnt = 
   	 new NavisionDocumentAuthorization.
   	 	PostedSalesShipment.PostedSalesShipment_Service(); 
	NavisionDocumentAuthorization.PostedSalesInvoice.
		PostedSalesInvoice_Binding posSalesInvoice = 
   		new NavisionDocumentAuthorization.
		PostedSalesInvoice.PostedSalesInvoice_Binding(); 
	public SalesHeader.SalesHeader[] NavisionSalesOrder() 
	{ 
	sh_serv.UseDefaultCredentials = true; 
	salesHeader = sh_serv.ReadMultiple(null, null, 0); 
	return salesHeader; 
	} 
	public Sales_Order_Line1[] NavisionSalesLine(string slectedSalesHeaderNo) 
	{ 
	SalesHeader_Binding slvc = new SalesHeader_Binding(); 
	sr = slvc.Read(slectedSalesHeaderNo); 
	return sr.SalesLines; 
	} 
	public void UpdateSalesLine
	(bool authorize, decimal authorizeQty, string documentNo, int index) 
	{ 
	SalesHeader.Sales_Orders sOs = 
		new NavisionDocumentAuthorization.SalesHeader.Sales_Orders(); 
	NavisionDocumentAuthorization.SalesHeader.Sales_Orders_Binding soB = 
 	 new NavisionDocumentAuthorization.SalesHeader.Sales_Orders_Binding(); 
	soB.UseDefaultCredentials = true; 
	sOs = soB.Read(documentNo); 
	SO.Sales_Order_Line sool = 
		new NavisionDocumentAuthorization.SO.Sales_Order_Line(); 
	soos.UseDefaultCredentials = true; 
	so1 = soos.Read(documentNo); 
	SO.Sales_Order_Line[] sol1 = so1.SalesLines; 
	sol1[index].Authorize = authorize; 
	sol1[index].Authorize_Qty = authorizeQty; 
	soos.Update(ref so1); 
	} 
	public void PostSOShipment(string documentNo) 
	{ 
	so1 = soos.Read(documentNo); 
	soos.PostOrder(so1.Key); 
	} 
	public void PostSOInvoice(string documentNo) 
	{ 
	so1 = soos.Read(documentNo); 
	soos.PostOrderInvoice(so1.Key); 
	} 
	public void PostSOShipInvoice(string documentNo) 
	{ 
	so1 = soos.Read(documentNo); 
	soos.PostOrderShipInvoice(so1.Key); 
	} 
	public NavisionDocumentAuthorization.PostedSalesShipment.
		PostedSalesShipment[] GetPostedSalesShipment(
  	  string SONo) 
	{ 
	posSalesShpmnt.UseDefaultCredentials = true; 
	PostedSalesShipment.PostedSalesShipment_Filter pSSF = 
	   new NavisionDocumentAuthorization.
	   	PostedSalesShipment.PostedSalesShipment_Filter(); 
	pSSF.Field = 
  	  NavisionDocumentAuthorization.PostedSalesShipment.
  	  	PostedSalesShipment_Fields.Order_No; 
	pSSF.Criteria = SONo; 
	PostedSalesShipment.PostedSalesShipment_Filter[] pssfFilters = 
  	 new NavisionDocumentAuthorization.
  	 	PostedSalesShipment.PostedSalesShipment_Filter[] {
  	 pSSF }; 
	return posSalesShpmnt.ReadMultiple(pssfFilters, null, 0); 
	} 
	public NavisionDocumentAuthorization.PostedSalesShipment.
		Posted_Sales_Shpt_Line[] GetPostedSalesShipBody(string shpNo) 
	{ 
	PostedSalesShipment.PostedSalesShipment_Service posSalesShpbdy = 
 	   new NavisionDocumentAuthorization.
 	   	PostedSalesShipment.PostedSalesShipment_Service(); 
	PostedSalesShipment.PostedSalesShipment posSH; 
	posSH = posSalesShpbdy.Read(shpNo); 
	return posSH.SalesShipmLines; 
	} 
	public NavisionDocumentAuthorization.PostedSalesInvoice.
		PostedSalesInvoice[] GetPostedSalesInvoice(
   	 string SONo) 
	{ 
	posSalesInvoice.UseDefaultCredentials = true; 
	NavisionDocumentAuthorization.PostedSalesInvoice.
		PostedSalesInvoice_Filter pSiQry = 
  	  new NavisionDocumentAuthorization.PostedSalesInvoice.
  	  	PostedSalesInvoice_Filter(); 
	pSiQry.Field = NavisionDocumentAuthorization.
		PostedSalesInvoice.PostedSalesInvoice_Fields.Order_No; 
	pSiQry.Criteria = SONo; 
	NavisionDocumentAuthorization.PostedSalesInvoice.
		PostedSalesInvoice_Filter[] pSiQrys = 
  	  new NavisionDocumentAuthorization.PostedSalesInvoice.
  	  	PostedSalesInvoice_Filter[] { pSiQry }; 
	return posSalesInvoice.ReadMultiple(pSiQrys, null, 0); 
	} 
	public NavisionDocumentAuthorization.PostedSalesInvoice.
		Posted_Sales_Invoice_Line[] GetPostedSalesInvBody(string InvNo) 
	{ 
	PostedSalesInvoice.PostedSalesInvoice_Binding posSalesInvbdy = 
  	  new NavisionDocumentAuthorization.
  	  	PostedSalesInvoice.PostedSalesInvoice_Binding(); 
	PostedSalesInvoice.PostedSalesInvoice posIn; 
	posIn = posSalesInvbdy.Read(InvNo); 
	return posIn.SalesInvLines; 
	} 
	} 
}

The above class contains the logic to fetch Navision Sales Order, Sales Shipment and Sales Invoice. It also contains the logic to post the Sales Order to Sales Shipment and Sales Invoice.

Development 7: Creating the “ViewSO” Form in C#

p6.JPG

Development 8: Creating the “PostedShipments” Form in C#

p7.JPG

Development 9: Creating the “PostedInvoices” Form in C#

p8.JPG

Development 10: Writing Code on Triggers of Buttons of “ViewSO” Form

C#
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
namespace NavisionDocumentAuthorization 
{ 
	public partial class frmAthSO : Form 
	{ 
	FetchNavisionSOP fetchnavisionSO = new FetchNavisionSOP(); 
	string selectedSONo = string.Empty; 
	bool authorize; 
	SalesHeader.Sales_Order_Line1[] SOL; 
	DataGridViewRow SalesLineRow = new DataGridViewRow(); 
	public frmAthSO() 
	{ 
	InitializeComponent(); 
	} 
	private void frmAthSO_Load(object sender, EventArgs e) 
	{ 
	datagridviewSalesHeader.DataSource = fetchnavisionSO.NavisionSalesOrder(); 
	datagridviewSalesHeader.EditMode = DataGridViewEditMode.EditProgrammatically; 
	datagridviewSalesHeader.Columns[0].Visible = false; 
	} 
	private void datagridviewSalesHeader_SelectionChanged
		(object sender, EventArgs e) 
	{ 
	selectedSONo = string.Empty; 
	DataGridViewRow row = new DataGridViewRow(); 
	row = datagridviewSalesHeader.CurrentRow; 
	selectedSONo = row.Cells[1].Value.ToString(); 
	datagridviewSalesLine.DataSource = 
		fetchnavisionSO.NavisionSalesLine(selectedSONo); 
	SOL = fetchnavisionSO.NavisionSalesLine(selectedSONo); 
	DataGridViewRow rowline = new DataGridViewRow(); 
	rowline = datagridviewSalesLine.CurrentRow; 
	datagridviewSalesLine.Columns[0].Visible = false; 
	} 
	private void datagridviewSalesLine_CellValueChanged(object sender, 
    	DataGridViewCellEventArgs e) 
	{ 
		try 
		{ 
		decimal authQty = 0; 
		SalesLineRow = datagridviewSalesLine.CurrentRow; 
		string aut = 
  		datagridviewSalesLine.Rows[SalesLineRow.Index].
  			Cells["Authorize"].Value.ToString(); 
		decimal.TryParse(
  		 datagridviewSalesLine.Rows[SalesLineRow.Index].
  		 	Cells["Authorize_Qty"].Value.ToString(),
    		out authQty); 
		fetchnavisionSO.UpdateSalesLine(Boolean.Parse(
  	 	datagridviewSalesLine.Rows[SalesLineRow.Index].
  	 		Cells["Authorize"].Value.ToString()),
  	 	authQty, selectedSONo, SalesLineRow.Index); 
		} 
		catch (Exception ex) 
		{ 
		MessageBox.Show(ex.Message,ex.HelpLink); 
		} 
	} 
	private void btnShip_Click(object sender, EventArgs e) 
	{ 
		try 
		{ 
		DataGridViewRow row = new DataGridViewRow(); 
		row = datagridviewSalesHeader.CurrentRow; 
		selectedSONo = row.Cells[1].Value.ToString(); 
		fetchnavisionSO.PostSOShipment(selectedSONo); 
		datagridviewSalesLine.DataSource = 
			fetchnavisionSO.NavisionSalesLine(selectedSONo); 
		MessageBox.Show("Sales order no. " + 
			selectedSONo + "Shipped", "Sales Shipment"); 
		} 
		catch (Exception ex) 
		{ 
		MessageBox.Show(ex.Message, ex.HelpLink); 
		} 
	} 
	private void btnInv_Click(object sender, EventArgs e) 
	{ 
		try 
		{ 
		DataGridViewRow row = new DataGridViewRow(); 
		row = datagridviewSalesHeader.CurrentRow; 
		selectedSONo = row.Cells[1].Value.ToString(); 
		fetchnavisionSO.PostSOInvoice(selectedSONo); 
		datagridviewSalesHeader.DataSource = fetchnavisionSO.NavisionSalesOrder(); 
		datagridviewSalesHeader.EditMode = 
			DataGridViewEditMode.EditProgrammatically; 
		datagridviewSalesHeader.Columns[0].Visible = false; 
		datagridviewSalesLine.DataSource = 
			fetchnavisionSO.NavisionSalesLine(selectedSONo); 
		MessageBox.Show("Sales order no. " + 
			selectedSONo + "Invoiced", "Sales Invoice"); 
		} 
		catch (Exception ex) 
		{ 
		MessageBox.Show(ex.Message, ex.HelpLink); 
		} 
	} 
	private void btnShipInv_Click(object sender, EventArgs e) 
	{ 
		try 
		{ 
		DataGridViewRow row = new DataGridViewRow(); 
		row = datagridviewSalesHeader.CurrentRow; 
		selectedSONo = row.Cells[1].Value.ToString(); 
		fetchnavisionSO.PostSOShipInvoice(selectedSONo); 
		datagridviewSalesHeader.DataSource = 
			fetchnavisionSO.NavisionSalesOrder(); 
		datagridviewSalesHeader.EditMode = 
			DataGridViewEditMode.EditProgrammatically; 
		datagridviewSalesHeader.Columns[0].Visible = false; 
		datagridviewSalesLine.DataSource = 
			fetchnavisionSO.NavisionSalesLine(selectedSONo); 
		MessageBox.Show("Sales order no. " + 
			selectedSONo + "Shipped & Invoice", 
		  "Sales Shipment & Invoice"); 
		} 
		catch (Exception ex) 
		{ 
		MessageBox.Show(ex.Message, ex.HelpLink); 
		} 
	} 
	private void btnPstdShip_Click(object sender, EventArgs e) 
	{ 
		try 
		{ 
		DataGridViewRow row = new DataGridViewRow(); 
		row = datagridviewSalesHeader.CurrentRow; 
		selectedSONo = row.Cells[1].Value.ToString(); 
		DataGrid dgPstdShp = new DataGrid(); 
		DataGrid dgPstbdy = new DataGrid(); 
		NavisionDocumentAuthorization.PostedSalesShipment.
			PostedSalesShipment[] psSalesShp; 
		dgPstdShp.DataSource = fetchnavisionSO.GetPostedSalesShipment
					(selectedSONo); 
		psSalesShp = fetchnavisionSO.GetPostedSalesShipment(selectedSONo); 
			if (psSalesShp.Count() > 0) 
			{ 
				dgPstbdy.DataSource = 
					fetchnavisionSO.GetPostedSalesShipBody
						(psSalesShp[0].No); 
				PostedShipments postdShipments = 
					new PostedShipments
					(dgPstdShp, dgPstbdy, true); 
				postdShipments.Show(); 
			} 
		} 
		catch (Exception ex) 
		{ 
			MessageBox.Show(ex.Message, ex.HelpLink); 
		} 
	} 
	private void btnPstInv_Click(object sender, EventArgs e) 
	{ 
		try 
		{ 
			DataGridViewRow row = new DataGridViewRow(); 
			row = datagridviewSalesHeader.CurrentRow; 
			selectedSONo = row.Cells[1].Value.ToString(); 
			DataGrid dgPstdInv = new DataGrid(); 
			DataGrid dgPstdInvBdy = new DataGrid(); 
			NavisionDocumentAuthorization.
				PostedSalesInvoice.PostedSalesInvoice[] psSalesInv; 
			dgPstdInv.DataSource = 
				fetchnavisionSO.GetPostedSalesInvoice(selectedSONo); 
			psSalesInv = 
			fetchnavisionSO.GetPostedSalesInvoice(selectedSONo); 
			if (psSalesInv.Count() > 0) 
			{ 
				dgPstdInvBdy.DataSource = 
					fetchnavisionSO.GetPostedSalesInvBody
					(psSalesInv[0].No); 
				PostedInvoices postdInvoices = 
					new PostedInvoices(dgPstdInv, dgPstdInvBdy); 
				postdInvoices.Show(); 
			} 
		} 
		catch (Exception ex) 
		{ 
			MessageBox.Show(ex.Message, ex.HelpLink); 
		} 
	} 
	} 
}

The above code contains the business logic to call the functions written in “FetchNavisionSOP” class so that all business logic of Navision SOP along with add-on “DocumentAuthorization” can be integrated.

Development 11: Writing Code on “PostedShipments” Class

C#
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
namespace NavisionDocumentAuthorization 
{ 
	public partial class PostedShipments : Form 
	{ 
		public PostedShipments() 
		{ 
			InitializeComponent(); 
		} 
		public PostedShipments(DataGrid dataGridSalesShp, 
				DataGrid dataGridSalesShpBody, 
  		bool postedSalesShip ) 
		{ 
			InitializeComponent(); 
			if (postedSalesShip) 
			{ 
				datagridviewPostedSalesShipments.DataSource = 
						dataGridSalesShp.DataSource; 
				datagridviewPostedSalesShipBody.DataSource = 
						dataGridSalesShpBody.DataSource; 
				datagridviewPostedSalesShipments.EditMode = 
					DataGridViewEditMode.EditProgrammatically; 
				datagridviewPostedSalesShipBody.EditMode = 
					DataGridViewEditMode.EditProgrammatically; 
				datagridviewPostedSalesShipments.Columns[0].
							Visible = false; 
				datagridviewPostedSalesShipBody.Columns[0].
							Visible = false; 
			} 
			else 
			{ 
			} 
		} 
		private void datagridviewPostedSalesShipments_SelectionChanged
			(object sender, EventArgs e) 
		{ 
			string selectedShpNo = string.Empty; 
			DataGridViewRow row = new DataGridViewRow(); 
			FetchNavisionSOP fetchnavisionSO = new FetchNavisionSOP(); 
			row = datagridviewPostedSalesShipments.CurrentRow; 
			selectedShpNo = row.Cells["No"].Value.ToString(); 
			datagridviewPostedSalesShipBody.DataSource = 
    			fetchnavisionSO.GetPostedSalesShipBody(selectedShpNo); 
		} 
	} 
}

The above code contains the business logic to instantiate the Datasource of the form.

Development 12: Writing Code on “PostedInvoices” Class

C#
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
namespace NavisionDocumentAuthorization 
{ 
	public partial class PostedInvoices : Form 
	{ 
		public PostedInvoices() 
		{ 
			InitializeComponent(); 
		} 
		public PostedInvoices(DataGrid dataGridSalesInv, 
					DataGrid dataGridSalesInvBody) 
		{ 
			InitializeComponent(); 
			dgPostedSalesInv.DataSource = dataGridSalesInv.DataSource; 
			dgPostedSalesInv.EditMode = 
				DataGridViewEditMode.EditProgrammatically; 
			dgPostedSalesInv.Columns[0].Visible = false; 
			datagridviewPostedSalesInvBody.EditMode = 
				DataGridViewEditMode.EditProgrammatically; 
			datagridviewPostedSalesInvBody.DataSource = 
						dataGridSalesInvBody.DataSource; 
			datagridviewPostedSalesInvBody.Columns[0].Visible = false; 
		} 
		private void dgPostedSalesInv_SelectionChanged
					(object sender, EventArgs e) 
		{ 
			string selectedInvNo = string.Empty; 
			DataGridViewRow row = new DataGridViewRow(); 
			FetchNavisionSOP fetchnavisionSO = new FetchNavisionSOP(); 
			row = dgPostedSalesInv.CurrentRow; 
			selectedInvNo = row.Cells["No"].Value.ToString(); 
			datagridviewPostedSalesInvBody.DataSource = 
					fetchnavisionSO.GetPostedSalesInvBody(
  			selectedInvNo); 
		} 
	} 
}

The above code contains the business logic to instantiate the Datasource of the form.

Now finally let’s have a demo.

Demo

a) Launch the C# application:

p9.JPG

Above forms contains all the List of Navision Sales Order. Currently, the user is on Sales Order No. 1001 and it has only one Sales Line associated.

When user will go to record “101009” of SalesOrder screen, the UI will be as follows:

p10.JPG

The above form contains two Sales Line item for Sales order “101009”.

b) Now, we will authoirze the Sales Order Line for Order No. 101015.

Before authorizing, if user will try to post the sales order or made some amendment in Sales “Qty to Invoice” or Sales “Qty to Ship” fields than it will raise an exception that “Sales Line is not authorized”.

p11.JPG

The above error will also occur when user will try to post from C# application, i.e.:

p12.JPG

c) Now we will authorize the Item No. “1896-S” for Sales Order No “101015” from C# application. This is the integration point of Navision Document Authorization in such way that Navision SO Line Items are authorized from C# application for a particular qty and can be posted from either Navision or from Navision Document Authorization application.

p14.JPG

When we change the record than Sales Line Item No 1896-S for SO “101015” is authorized, i.e.:

p15.JPG

In the above picture, one can notice that line no. 6 of second grid for Sales Order No. 101015 is authorized. This addon has a feature to authorized the sales line for a particular qty. It means that when the sales line is authorized for a particular qty, then the user cannot post the sales line above authorization level either from Navision or “Authoirze Navision Sales Order” Add-on.

d) Now, authorize the Sales Line for qty. 10 of Order No. 101015 right from “Authoirze Navision Sales Order” add-on

p16.JPG

If you open the Sales Order in Navision, then one can observe that sales Qty is 15 but the authorized qty. is 10. It means that one cannot post the sales qty more than 10 for Line No. 6 i.e.

p17.JPG

In the above picture, one can see that the authorized qty. is 10 and it is uneditable. This authorization can only happen through Navision Document authorization Add-On. This feature states that if any ISV, client is having add-on already then why anybody will go and develop the same functionality in Navision from Scratch. This type of integration is so easily possible due to Microsoft, as they had released Navision 2009 SP1 and in that, they had exposed all Navision pages and codeunits by using windows communication framework architecture.

e) Now, if user tries to post the Sales Line no. 5 for SO no. 101015 then the SO will posted either to Shipment or Invoice or both depending upon the user choice. Another interesting integration I had provided to “Navision document authorization” Add-On is that any user can post SO to shipment and Invoice from addon it self. This feature also gives the any ISV, partner or Client a feature to do both ways integration. Navision to Add-On and Add-On to Navision. In our case Navision to NDA (Navision Document Authorization) Add-On and vice versa.

Almost for 7 years, I am quite bored by posting the Navision Sales order from Navision only, this time I would like to have some change so I decided to post from my NDA add-on…

One can notice that, either user can post to shipment only and then invoice or directly to ship and invoice. So I prefer to post directly to Post and Invoice.

First, let us try to qty more than authorize qty. from Navision.

p18.JPG

In the above picture, one can notice that it pops up error that “Qty. to ship 11 cannot be greater than Authorized Qty 10.”. Hence we are on the right path as Authorized Qty on Addon for this line is 10 and this information is also available on Navision screen. So, now try to post for 8 qty.

p19.JPG

In the above picture, I change the qty. to 8 for last record of SO 101015 and it doesn’t pop up the error.

No we will try to post the order from NDA add-on.

p20.JPG

p21.JPG

p22.JPG

Hence our sales order 101015 is shipped and invoice for authorize qty. 10.

f)

Now right from NDA add-on, one can peep into Posted Shipment and posted Invoices without going into Navision. Just click over Posted Shipments button on NDA Add-on.

p23.JPG

So one can see in the above picture there are 5 no of shipments for SO no. 101015 and our shipment no. that we posted just now is 102045 for 8 qty.

g)

Now right from NDA add-on, one can easily peep into Posted invoices without going into Navision. Just click over Posted Invoices button on NDA Add-on.

p24.JPG

So one can see in the above picture that there are 3 no. of shipments for SO no. 101015 and our Invoice no. that we posted just now is 103023 for 8 qty.

Takeaways from this Add-On

  1. ISVs , clients and Developers can easily integrate their addon to Navision for leveraging existing functionality to Navision.
  2. ISVs, clients and developers can easily understand the easiest approach to integrate the Navision with any Add-on in the world, i.e., by using windows communication framework architecture.
  3. ISVs, clients and developers can change their old architecture(Automation for Navision) for their add-on to the new architecture defined in this article with source code.
  4. Important- Now, there is no need to develop any functionality in Navision CSIDE code. Just decide at what point we can integrate the functionality that is developed in other platform to navision and provide the one universal adapter such that our add-on can be integrate to Navision and other ERPS like Axapta, SAP, Peoplesoft, etc. Please note that this add-on is developed in such a way that it can be connected to Axapta and other ERPS to by just changing small piece of code.
  5. As in the beginning said, now we can develop any business functionality by using WPF, WCF , C#, Silverlight, Azax and XML and thus easily integrate it with Navision 2009 SP1 by using the approach define in this NDA add-on. Recently Microsoft had released Navision 2009 R2 release which has rendered the Navision ERP over Web(Internet), hence in my Next NDA R2 release, I will be migrating the whole architecture of this article to Navision 2009 R2 and thus demonstrating that how easily one can rendered their add-on over net with Navision 2009 R2 and thus entering the wole new world of cloud computing.
  6. Now any customization for adding new functionality in Navision for clients can easily be developed in .NET as defined in this article, which will save the implementing partner expensive Navision objects cost.

Coming Soon

Recently Microsoft had released Navision 2009 R2 release which has rendered the Navision ERP over Web(Internet), hence in my Next NDA R2 release, I will be migrating the whole architecture of this article to Navision 2009 R2 and thus demonstrating that how easily one can rendered their add-on over net with Navision 2009 R2 and thus entering the whole new world of cloud computing.

So wait for next NDA R2 (Release-2) Release, soon…

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalhi Pin
sinhanu13-May-11 0:46
sinhanu13-May-11 0:46 
GeneralRe: hi Pin
abhishek pareek200916-Jun-11 22:01
abhishek pareek200916-Jun-11 22:01 
Generalnice one Pin
Pranay Rana22-Dec-10 23:10
professionalPranay Rana22-Dec-10 23:10 
nice one
For any question : http://pranayamr.blogspot.com/

vote my article :

Learn SQL to LINQ ( Visual Representation )


Calling WCF Services using jQuery

GeneralRe: nice one Pin
abhishek pareek200923-Dec-10 3:01
abhishek pareek200923-Dec-10 3:01 
GeneralMy vote of 5 Pin
navdev22-Dec-10 19:12
navdev22-Dec-10 19:12 
GeneralRe: My vote of 5 Pin
abhishek pareek200923-Dec-10 3:01
abhishek pareek200923-Dec-10 3:01 
QuestionWhat is Navision, and Other Stuff Pin
#realJSOP22-Dec-10 2:42
mve#realJSOP22-Dec-10 2:42 
AnswerRe: What is Navision, and Other Stuff [modified] Pin
RAND 45586622-Dec-10 2:53
RAND 45586622-Dec-10 2:53 
GeneralRe: What is Navision, and Other Stuff Pin
#realJSOP22-Dec-10 5:10
mve#realJSOP22-Dec-10 5:10 
GeneralRe: What is Navision, and Other Stuff Pin
abhishek pareek200922-Dec-10 18:37
abhishek pareek200922-Dec-10 18:37 
AnswerRe: What is Navision, and Other Stuff Pin
HaBiX22-Dec-10 21:02
HaBiX22-Dec-10 21:02 
GeneralRe: What is Navision, and Other Stuff Pin
abhishek pareek200923-Dec-10 3:02
abhishek pareek200923-Dec-10 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.