Getting Started with VST: WinForms and Controls – Part 2

August 7, 2009

Well, getting back on track with our series, today I will show you how to add the toolbar and status bar button controls in addition to adding the code that will allow our WinForm to be displayed as an menu option under the Additional menu on the Customer Maintenance window.

1) In the Toolbox window, choose Button

2) Click on the toolbar area of the window to place the button control. Then change the properties as indicated in the picture below:

Note that the ButtonType on dexButtonProvider property is implemented as part of the Microsoft Dexterity Shell assembly (Microsoft.Dexterity.Shell.dll). Also, note that when I set the value to ToolbarWithSeparator the button immediately acquired the “look and field” of a typical Dexterity toolbar button.

3) Now, let’s add the image to the Ok button. To do this, we can click on the image property and select the picture resource that best suit our needs:

In this case, I selected the Toolbar_Post image in the Resources file. Now, you can choose to add the actual checkmark image as part of the existing resources, but that is not a topic of this article.

4) On your own, add the window help button and the window note present and window note absent buttons to the status bar. For these controls, you will want to change the ButtonType on dexButtonProvider property to StatusArea and remove clear the text in the Text property. Don’t forget to stack the the note buttons! The final result should look like the picture below:

5) Now that we have finalized the window layout, let’s add some code to create the equivalent of a Dexterity form trigger. This will create an Additional menu on the Customer Maintenance window, allowing us to open the form. In VST, Dexterity form triggers are known as Menu Handler events and need to be registered in the Initialize() method in the GPAddIn.cs class.

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;

namespace GPWinForm
{
public class GPAddIn : IDexterityAddIn
{
// Add a variable reference to the RM Customer Maintenance form
static RmCustomerMaintenanceForm CustomerMaintenanceForm = Dynamics.Forms.RmCustomerMaintenance;

// Keep a reference to the rmCustomerHobbies WinForm
static rmCustomerHobbies rmCustomerHobbiesForm;

public void Initialize()
{
CustomerMaintenanceForm.AddMenuHandler(OpenRMCustomerHobbies, "Customer Hobbies", "H");
}

static void OpenRMCustomerHobbies(object Sender, EventArgs e)
{
// check to make sure the form is not either empty or already created
if (rmCustomerHobbiesForm == null)
rmCustomerHobbiesForm = new rmCustomerHobbies();
else
if (rmCustomerHobbiesForm.Created == false)
rmCustomerHobbiesForm = new rmCustomerHobbies();

rmCustomerHobbiesForm.Show();
rmCustomerHobbiesForm.Activate();

}
}
}

A couple things to note. In this script, we added static references to the Customer Maintenance form and rmCustomerHobbies WinForm to facilitate interacting with these throughout our code:


// Add a variable reference to the RM Customer Maintenance form
static RmCustomerMaintenanceForm CustomerMaintenanceForm = Dynamics.Forms.RmCustomerMaintenance;

// Keep a reference to the rmCustomerHobbies WinForm
static rmCustomerHobbies rmCustomerHobbiesForm;

We also added the menu handler event to assist in displaying a menu option to call our WinForm from the Customer Maintenance window. The OpenRMCustomerHobbies event handler method is the equivalent of a trigger processing procedure in Dexterity:


CustomerMaintenanceForm.AddMenuHandler(OpenRMCustomerHobbies, "Customer Hobbies", "H");

In Dexterity, the open form statement does a few things: it opens the form, activates the form, and open the main window of that form, if the AutoOpen property of the window is set to True . In VST, we can accomplish the same in two steps, by invoking the Show() and Activate() class methods of the form object.


rmCustomerHobbiesForm.Show();
rmCustomerHobbiesForm.Activate();

With the instructions provided in Part 1 of the WinForms and Controls series, we can proceed to build and deploy our assembly (I did not change the assembly name for this project). Once you load GP, open the Customer Maintenance window (Cards > Sales > Customer) to test the solution. You should now see the Additional menu option, along with our Customer Hobbies entry.


If you select the option, you should now see our form. Granted, we haven’t added any code to manage whether a record was selected or not prior to our form being opened, we did not add any code to preset the Customer ID and Customer Name fields on our WinForm based on the same field values on the Customer Maintenance window, and certainly have not added any code to retrieve or store data based on the selected customer. All this will be a part of our next article.

Downloads

GPWinForm solution – C# – Click here

Related Articles

Getting Started with VST: WinForms and Controls – Part 1
Getting started with VST: “Hello World!” – The Video
Getting started with VST: “Hello World!” project
Getting started with Visual Studio Tools for Microsoft Dynamics GP — Adventures of a Microsoft Dexterity developer

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/

Advertisements

Getting Started with VST: WinForms and Controls – Part 1

July 31, 2009

If you have been around Microsoft Dexterity long enough, by now you are already aware that Dex is not an object oriented development environment, and rather supports a concept called object-based development. In the traditional sense, Dexterity does not allow you to define classes and derive objects from those classes. However, someone figured out that a Dexterity form can act as a container or class, with the Scripts and Functions tabs allowing you to define the contructors, destructors and methods for the class. In addition, adding fields to a window and setting the proper values for those fields allows developers to set the state of an object. Given the nature of the form and how the scripts on that form are called, and the values for fields on windows are set, forms can simulate classes with public and private methods in traditional object oriented programming terms.

Thank goodness, you don’t need to do all this in Visual Studio! VST allows you to define a WinForm, or in simple terms, a Windows Form. Forms in VST cannot be grouped as you would normally do in Dexterity, so in that sense, they behave like typical Dexterity window, but they still provide all the functionality, including the look and feel due to the inherited properties created with the Dexterity Bridge assembly.

Customer Hobbies WinForm

Our example today, will show how to add the equivalent of a Dexterity form trigger, known in VST as a menu handler event. Typically, form triggers add an entry to the Additional menu on a Dexterity form. Today, we will add a Customer Hobbies form and will then add a menu handler event to the Customer Maintenance form to call our form.

1) Open Visual Studio. Go to File > New > Project to create a new Visual Studio project.

2) Find the Dynamics GP in the Project Types pane, then choose Microsoft Dynamics GP Add-In from the installed templates pane.

3) Enter a name for the project. We will be naming our project GPWinForm.

4) Click OK to continue

5) Make sure your GPAddIn.cs code looks like this:

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;

namespace GPWinForm
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface

public void Initialize()
{

}
}
}

6) We will first define our WinForm. In Solution Explorer, right-click on the project name and navigate to Add > New Item as shown in the figure below.

7) In the Add New Item window we will highlight Microsoft Dynamics GP Form and name our form rmCustomerHobbies.cs. Click on Add to continue.

8) Here comes VST into play! When the form is defined, you will notice a set of providers at the bottom of the design window, as shown below.

These providers allow WinForms and certain controls to inherit properties unique to Dexterity windows and controls. In the example, our WinForm is given a Control area and a Status area by default. To change the window title, locate the Text property in the Properties window and edit to Customer Hobbies.

9) Now, let’s add some controls — you will need to resize your window accordingly. We will add a few prompts (known as labels in Visual Studio) and a few strings (known as text boxes in Visual Studio). First our text boxes:

a) Click on the TextBox control in the Toolbox. We will add the CustomerNumber field. Set the properties for the field as follow:


b) Now, let’s add the CustomerName field. We can follow the same steps used in (a). At the end your window should look like this:


In traditional Dexterity style, these two fields will inherit the values displayed in the Customer Maintenance window when a record is selected and the Customer Hobbies window is selected.

10) Now we can add the labels that will identify our fields when the window is opened. We will add the Customer ID and Customer Name labels, but most importantly, show how you can link fields to their prompts as well, just like in Dexterity.

a) Click on the Label control in the Toolbox. Now place the label in from of the CustomerNumber field. Size the label accordingly and align accordingly. Set the label properties as follow:

NOTE: Unlike Dexterity, label controls are referenciable via code, hence the Name property of the control.

b) Repeat step (a) for the Customer Name label and set the propeties as well.


11) Now let’s proceed to link the fields to their prompts. One of the properties unique to VST label controls is the LinkField on dexLabelProvider. This property will display a drop-down list that will allow you to select the corresponding window field for the label, as shown below:


Once a label is linked to a textbox, you will see the traditional underline that accompanies all Dexterity prompts.

12) Following the same guidelines, we will add 4 more text boxes, rmCustomerSports, rmCustomerSportsTeam, rmCustomerLeisureActivity, and rmCustomerRestaurant, and the corresponding labels to indicate the customer’s hobbies. Note that the Enabled property for these new controls must be set to True to allow the controls to receive data. We will also use an empty label from the Toolbox to create the separator between the window’s static section and the data entry section, a la Dexterity. Your final window should look like this — don’t worry if you did not get the same results, I have uploaded the solution for your benefit.


Part 2 of the “WinForms and Controls” series will discuss adding the typical buttons to the screen, like the Ok button, the window help button and the window notes buttons. In addition to the code needed to produce the menu handler event.

Downloads

GPWinForm Solution – click here.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/

Updates to this article
08/07/2009 – Fixed broken link to solution download.


Getting started with VST: "Hello World!" – The Video

July 24, 2009

Getting started with VST: "Hello World!" project

July 21, 2009

Adventures of a Microsoft Dexterity Developer

Okay, so we did not get this far to bring up a “Hello World” message, but I figured that’s a pretty standard thing to do in the software development world to introduce a tool or language to software developers, so I am not going to pass upon the chance!

Creating our first Visual Studio Tools project… with a twist!

For this project, we want to be able to register two events that will allow us to display the messages “Getting ready to say Hello World!” and “Hello World” messages after login is successful and before and after the Toolbar form is loaded. Usually, this method of trigger registration is used by Dexterity developers to run code after log in, so I figured I would replicate something we are most familiar with.

Topics being covered

  • Creating a VST project
  • Events registration
  • Running your code before and after login
  • Building and Deploying VST project

Let’s get started!

1) Open Visual Studio. Go to File > New > Project to create a new Visual Studio project.

2) Find the Dynamics GP in the Project Types pane, then choose Microsoft Dynamics GP Add-In from the installed templates pane.

3) Enter a name for the project. We will be naming our project GPHelloWorld.

4) Click OK to continue.


NOTE: As indicated, I will be using C# as my development language, however, the steps to initiate the project for VB.NET should be the same.

5) Upon clicking OK, Visual Studio will proceed to initialize our project for us. The first thing you will see is the Initialize() method in the GPAddIn class. The GPAddIn is an implementation of the IDexterityAddIn interface. Sufficient to say, the Initialize() method is equivalent to the global Startup script in a Dexterity integrating application, serving as entry point to the add-in project.

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;

namespace GPHelloWorld
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface
public void Initialize()
{

}
}
}

NOTE the Solution Explorer window will show the references to the primary assembly responsible for exposing Dynamics GP resources: the Microsoft.Dexterity.Bridge assembly. As well, you can find all picture resources that will make our VST controls look awefully similar to the standard controls available to integrating Dexterity applications.

6) Now, we will proceed to register the event on the Toolbar form. We will display a message “Getting ready to say Hello World!” before the toolbar form is loaded and one that says “Hello World!” after the toolbar is loaded. You can then decide what event works best for your individual needs.

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;


namespace GPHelloWorld
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface
public void Initialize()
{
ToolbarForm toolbar;
toolbar = Dynamics.Forms.Toolbar;

// add registration before the form open event
toolbar.OpenBeforeOriginal += new System.ComponentModel.CancelEventHandler(toolbar_OpenBeforeOriginal);

// add registration after the form open event
toolbar.OpenAfterOriginal += new EventHandler(toolbar_OpenAfterOriginal);
}

void toolbar_OpenBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("Getting ready to say Hello World!");
}

void toolbar_OpenAfterOriginal(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");

}
}
}

A couple things to highlight in the code:

a) Like references in Dexterity, VST allows you to create variables that point to specific dictionary resources. The definitions for the various dictionary resources are found in an additional namespace available in the application assembly, Microsoft.Dexterity.Applications.DynamicsDictionary.


using Microsoft.Dexterity.Applications.DynamicsDictionary;

Once the namespace is added, you can then proceed to declare a variable that will represent the Toolbar form.


public void Initialize()
{
ToolbarForm toolbar;
toolbar = Dynamics.Forms.Toolbar;
.
.
}

b) An event registration is the Visual Studio equivalent of a Dexterity trigger. As such, they must be included in the Initialize() method, added automatically when the project was created. The Initialize() method is the equivalent of the Startup() script in a Dexterity integrating application. To register the events that will be executed before and after the Toolbar form is loaded, the following code was added,


// add registration before the form open event
toolbar.OpenBeforeOriginal += new System.ComponentModel.CancelEventHandler(toolbar_OpenBeforeOriginal);

// add registration after the form open event
toolbar.OpenAfterOriginal += new EventHandler(toolbar_OpenAfterOriginal);

If you noticed when you typed the += character sequence, you were prompted to press the TAB key twice! Intellisense automatically completed the code and added the overload methods for each event handler. Now, that’s a time saver! Imagine if we had this type of capability when adding the trigger registration scripts in Dexterity!

c) The rest was just cosmetics.. I added the MessageBox.Show() function to display our two messages in each overload method. The MessageBox is part of the System.Windows.Forms namespace which must be added to the using section of the application.


void toolbar_OpenBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)

{
MessageBox.Show("Getting ready to say Hello World!");
}

void toolbar_OpenAfterOriginal(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");
}

Simple enough!

7) Building the solution is done via the Build menu, but before, we can set our final assembly name by right-clicking on the GPHelloWorld project in the Solution Explorer window and selecting the Properties option.

8) Build the solution. You should be able to find your new assembly in the Bin\Debug folder of the solution directory, typically under C:\Users\yourUser\Documents\Visual Studio 2008\Projects\GPHelloWorld\GPHelloWorld\bin\Debug.

Copy the resulting project assembly to the AddIns folder under your Microsoft Dynamics GP installation directory.

Testing the solution

Open Microsoft Dynamics GP to see the results. Before the Toolbar form is loaded, we will receive the first message:

Once the Toolbar form is loaded, our next message will be displayed, as follows:


I guess this is not bad for a first try, is it?

While integrating solutions tend to be a lot more complex than our Hello World application, the principles will be the same. For our next installment, I will be contructing a WinForm and showing common ways to store and retrieve data in a VST solution.

Downloads

HelloWorld Solution C# – Click here
HelloWorld Solution VB.NET – Click here

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


Getting started with Visual Studio Tools for Microsoft Dynamics GP — Adventures of a Microsoft Dexterity developer

July 20, 2009

For the longest time I had been trapped in my own Microsoft Dexterity development shell and could not see why anyone would want to integrate to Dynamics GP with anything that is not Dexterity — I am not referring to simple customizations here! After all, Dexterity is (and will continue being for years to come!) the native development environment of Dynamics GP. So, the next obvious question in my mind was, why couldn’t .NET developers learn Dexterity? After all, we were here first! But, then I decided to spin the question around, why couldn’t Dexterity developers learn .NET? Now, that’s a challenge I like!!

In the next 2 weeks I will publish a set of articles showing Dexterity developers that it is possible to make a relatively smooth transition to .NET development with Visual Studio Tools for Microsoft Dynamics GP — by far, the longest name for any Microsoft product, so we will shorten that to VST.

The similarities

What you will find as a Microsoft Dexterity developer transitioning to VST is that you can do a lot of the things you are able to do when building integrating applications: an integrating application can access the forms, windows, window fields, tables, and table fields in each dictionary. They can also access global variables, commands, procedures, and functions defined in each dictionary. So from a Dexterity developer’s perspective you will be able to write the equivalent of triggers — known as event registrations in VST — on any resource in GP’s dictionary or a third party dictionary. You will be able invoke existing global procedures and functions, form procedures, etc.

In addition, VST provides the ability to develop WinForms. WinForms included in an integrating application can use capabilities provided by VST to match the appearance of the core application widows. The appearance of the window as well as the various controls in the window can be customized, just like windows created in a Dexterity application. In fact, you can also set the famous Control Area for which Dexterity windows are widely known. Finally, with the latest release of VST, you can now access Dynamics GP tables without using any data access technology, like ADO.NET for example.

As I move through the articles, I will reference the equivalent Dexterity terminology where needed to ensure you keep track of the similarities.

The Differences

From a pure architecture perspective, Dexterity resources reside in a dictionary. With VST your compiled code will reside in an assembly. An assembly is a fundamental building block of any .NET Framework application. From a coding perspective, Visual Basic.NET (VB.NET) and C# (pronounced C-sharp) will serve as replacements to Sanscript.

In summary, assembly is to dictionary as Visual Studio is to Dexterity as C# or VB.NET are to Sanscript.

What you will need

The following are the ingredients for this series of articles:

1) A valid copy of Visual Studio 2008
2) An installed copy of Microsoft Dynamics GP v10 with the Fabrikam company
3) Microsoft .NET Framework 2.0 or grater.
4) Intermediate to advance knowledge of Microsoft Dexterity
5) Click here to download Visual Studio Tools SDK SP3 for Microsoft Dynamics GP 10.0. The SDK contains the components to build integrations. Once downloaded proceed to install.

What to expect from these articles

A big disclaimer goes out to all of you Dexterity developers who will hopefully follow these articles:

1) This is not a proclamation of independence from Dexterity, rather a way to show you how to achieve some of the same integration capabilities with VST. Dexterity is a good skill to have and in today’s world will keep you rightfully and gainfully employed. After all, we are a specie in way to extinction and like Bigfoot (if you believe in such thing), very hard to find. But like all species in way to extinction, if you don’t reinvent yourself or learn other skills you probably won’t make it.

2) These articles will not show you how to code in C# or VB.NET, rather the integration mechanisms available with VST and how they are similar to what you currently do in Dexterity. As with any new programming language, you must have fairly good programming skills. The rest comes with a lot of reading, trying, frustrating yourself, and trying again, ah… and a good search engine — similar to how you learned Dexterity in the first place.

3) All the code for these articles will be written in C# like any world class commercially available application — no offense to VB.NET developers intended here — however, I will make a big effort to insert VB code snippets along with the C# code.

Please stay tuned for the series… the first article goes out tomorrow!

Series Links

Jul 21, 2009. Getting Started with VST: “Hello World!” project – Click here
Jul 24, 2009. Getting Started with VST: “Hello World!” – The video – Click here
Jul 31, 2009. Getting Started with VST: WinForms and Controls – Part 1 – Click here
Aug 07, 2009. Getting Started with VST: WinForms and Controls – Part 2 – Click here

Until next post!

MG.-
Mariano Gomez, MIS, MCP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


All about the Dexterity OLE Container

November 26, 2008

Much has been asked about the Microsoft Dexterity OLE Container lately and I wanted to address this topic by providing some background on the technology and how it is used from GP. In addition, I will address how to automate OLE externally from other applications.

Definition

In principle, OLE is a compound document technology from Microsoft based on the Component Object Model (COM). OLE allows an object such as a graphic, video clip, spreadsheet, etc. to be embedded into a document, called the Container Application. If the object is playable such as a video, when it is double clicked by the user, a media player is launched. If the object is allowed to be edited, the application associated with it (the Server Application) is launched.

An object can be linked instead of embedded, in which case the Container Application does not physically hold the object, but provides a pointer to it. If a change is made to a linked object, all the documents that contain that same link are automatically updated the next time you open them. An application can be both client and server, called an Object Packager, which is not something I will cover in this article.

History of OLE

OLE 1.0, released in 1990 and was capable of maintaining active links between two documents or even embedding one type of document within another. The server and client libraries, OLESVR.DLL and OLECLI.DLL, were originally designed to communicate between themselves using the WM_DDE_EXECUTE message. OLE 2.0 followed in the steps of OLE 1.0, sharing many of the same design goals, but was re-implemented on the COM platform. New features were automation, drag-and-drop, in-place activation and structured storage.

OLE custom controls were introduced in 1994 as a replacement for the Visual Basic Extension controls. In particular, any container that supported OLE 2.0 could already embed OLE custom controls, although these controls cannot react to events unless the container supports this. OLE custom controls are usually shipped in the form of a dynamic link library with the .ocx extension. In 1996 all interfaces for controls (except IUnknown) were made optional to keep the file size of controls down, so they would download faster.

The Dexterity OLE Container

The Dexterity OLE Container is part of the Dexterity Shared Components. In OLE compound document technology, it is the OLE client application (CONTAIN.EXE), which holds the linked or embedded objects. The Dexterity OLE Container first surfaced with the release of Dexterity 3.0 in 1993.

The Dexterity OLE Container can be opened via most record notes windows in the Dynamics GP application, by clicking on the paperclip button.

Dexterity OLE Container linked or embedded objects are stored in the path indicated by the OLEPath key in the DEX.INI file.

The following is a typical DEX.INI file layout:


[General]
.
.
OLEPath=C:\Notes\
.
.

When an object is linked or embed in the Dexterity OLE Container window for the first time, Dynamics GP will append the Intercompany ID‘\OLENotes to the OLEPath directory to create a unique physical storage directory for each object attached or embedded to a record note. In turn, the note index value associated to the record note serves as a file reference to the OLE object, this is an 8-character hexadecimal file name is created with the hexadecimal value of the note index.

For example, if the note index associated to the record is 16, a file name is created with the name 00000010.

The note index is also stored in the Records Notes Master table (SY03900) and a text is appended to the note in GP with the legend “OLE Link present”.


SELECT NOTEINDX, DATE1, TIME1, DEX_ROW_ID, TXTFIELD FROM SY03900

The query will produce the following resultset:


NOTEINDX DATE1 TIME1 DEX_ROW_ID TXTFIELD
--------------------------------------- ----------------------- ----------------------- ----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
16.00000 2008-11-28 00:00:00.000 1900-01-01 15:31:26.000 1 OLE Link present.

(1 row(s) affected)

The following is the physical file representation.

*Click on image to enlarge

NOTE: The next note index value is obtained from NOTEINDX column, in the company master table, DYNAMICS.dbo.SY01500.

Unfortunately, the Dexterity OLE Container application was designed only to work from within Microsoft Dynamics GP, hence no programmatic interface was created to support external integrations from other applications. There are no command lines to the CONTAINER.EXE application, however there are a few DDE commands available: Open, Close, Delete, Save. These correspond to the Dexterity OLE function library to control the OLE Container.

The Dexterity OLE Container does not make use of the Microsoft OLE Container Control, and was implemented as a C/C++ based application. Other sources have alluded to the fact that it was implemented based on an MSDN container sample.

Related Articles

KB article 268470 – “Sample: FramerEx.exe Is an MDI ActiveX Document Container Sample Written in Visual C++”, Microsoft Support.

Visual C++ Samples – OCLIENT Sample: Illustrates a Visual Editing Container Application. Microsoft Developer’s Network (MSDN).

Visual C++ Samples: DRAWCLI Sample: Illustrates Integrating Active Container Support with Application-Specific Features. Microsoft Developer’s Network (MSDN).

While the Dexterity OLE Container is not of much help as an external application, you can always run the CONTAIN.EXE application, then drag-and-drop any of the hexadecimal file references to the application’s desktop. In turn this will open the linked or embedded objects.

In my next installment, I will show you how to automate the OLE Container from other applications in order to read standard Dynamics GP OLE notes.

Until next post!

MG.-
Mariano Gomez, MIS, MVP, MCP, PMP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


Retrieving an eConnect XML Message from MSMQ

May 27, 2008

A common issue with eConnect’s development is the ability to retrieve messages extracted with the eConnect Requester service from an MSMQ queue. While most developers will be able to setup the Requester Service to extract data from Microsoft Dynamics GP, most will find it hard to retrieve those messages from their integrating solutions. The following VB.NET code shows a quick and efficient way of doing just that.


Private Sub GetMessage()
'Create queue object to retrieve messages from the default outgoing queue
Dim MyQueue As New MessageQueue(".\private$\econnect_outgoing9")

'Create an MSMQ formatter and transaction objects
MyQueue.Formatter = New ActiveXMessageFormatter

Dim MyTransaction As New MessageQueueTransaction

'Create a message object
Dim MyMessage As Message

Try
'Retrieve a message from the queue
'This example assumes there is always a message waiting in the queue

MyTransaction.Begin()
MyMessage = MyQueue.Receive(MyTransaction)

MyTransaction.Commit()

'Retrieve the string from the message

Dim MyDocument As [String] = CType(MyMessage.Body, [String])
'Load the string into an XML document object

Dim MyXml As New XmlDocument
MyXml.LoadXml(MyDocument)

'Display the XML from the queue message
MessageText.Text = MyXml.InnerXml
Catch err As SystemException

ErrorText.Text = err.InnerException.ToString()
End Try
End Sub

To summarize, it will be necessary to perform the following steps to extract a message from an MSMQ queue with your .NET application:

1) Create the queue object pointing to the eConnect queue
2) Create an MSMQ formatter and the correspoding transaction objects
3) Create a Message object
4) Retrieve the message from the queue
5) Retrieve the particular strings from within the message

From there on you can do anything with the information retrieved. In my example, I just chose to display the XML content of the message, but you can chose to pass this information to your application to perform any actions or store into some database table along with other info.

Until next post!

MG.-
Mariano Gomez, MIS, MCP, PMP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/