“Copy” any field from any Dynamics GP window using Dexterity SDK

I usually spend maybe 30-60 minutes Google-ing something before I just give up and write code to do it. For all I know there is a better way to go about this but this is my approach. In the famous words of James May, I would classify this as “an ingenious solution to a problem that should never have existed in the first place” (RIP Top Gear).

I have always wondered why you couldn’t select data in windows in Dynamics GP. Theft? Because that would make life too easy and we have to make sure there is still enough work for accounting technicians to do at the end of the day before robots take over? Regardless I wrote a short C# procedure that grabs the current window and dumps all non-empty fields into a nice data grid view that IS copyable. Needless to say this does not output data in scrolling windows as that is a separate window from the main window (although just as easy to copy from). As this is written as an add-in, you have to add the menu handler to each window you would like this on, but because I love coding in a very universal matter, no extra parameters or changes are required when calling the procedure from a new window.

Now for the code walkthrough (complete code provided below):

Grab the current window

static void displayDetails(object sender, EventArgs e){
Microsoft.Dexterity.Bridge.DictionaryForm currForm = sender as Microsoft.Dexterity.Bridge.DictionaryForm;

When you call a procedure from any window in GP, the SDK sends the reference to that form through the sender object

Create our data table

DataTable dt = new DataTable();
dt.Columns.Add(“Name”, typeof(String));
dt.Columns.Add(“Value”, typeof(String));

Loop through each field in the window

foreach (var field in currForm.Windows[0].Fields)

I left the index at 0 because for the most part I am just interested in the main window which is *usually* 0. You could add a form name check here to see if it matches the sender’s name to check for the main window to make this more robust

Loop through each property in the field hunting for the Name and Value

foreach (var prop in field.GetType().GetProperties()){
switch (prop.Name){
case “Name”:
name = prop.GetValue(field, null).ToString();
case “Value”:
value = prop.GetValue(field, null).ToString();
break; } }

Save the results to the data table

if ((name != “”) && !(String.IsNullOrEmpty(value))) {
DataRow row = dt.NewRow();
row[“Name”] = name;
row[“Value”] = value;
dt.Rows.Add(row); }

The only “hard-coded” aspects of this code are the property values “Name” and “Value” which I think is fairly safe to say are not going to change anytime soon. I created a form that stores my datagridview and bind the data table to that view. I also set the shortcut to close the form to CTRL-Q (same shortcut used to execute the code). This allows the user to quickly open and close it using the same shortcut. The other benefit of being a separate form is that you can navigate away from the original form but leave the Details_Form open for reference. I did not provide a .dll as it is up to you what windows you want to add this to but if there is anyone who wants me to build it based on a list of windows, comment below.

Code: Display Details.txt

Screenshot (blanked out sensitive information):




Disclaimer: I am very much an amateur programmer. I have never taken an official Microsoft course. I cannot guarantee any code/program that I provide as I only have the ability to test my work on a small sample set. Users accept all the risk of using anything I provide and are encouraged to thoroughly test in a dedicated test environment before moving to production. Files I provide are free for use and are not to be resold. By using my files you agree to not hold me liable for any damages caused by said files.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s