?
Solved

MS Dynamics GP VS # capture event

Posted on 2012-12-24
8
Medium Priority
?
687 Views
Last Modified: 2012-12-27
I am trying to catpure the event when someone changes the selling unit price on the sales order transaction entry screen. Since this field appears to be a local field and gets refreshed even when you move from one line to another I am having trouble isolating the capture to the event just when a user is sitting on it and changes its value.

sopEntryWindow.LineScroll.LocalUnitPrice.Change += new EventHandler(CheckForLineValueChanges);

I have tried different variations of this code in my VS C# program and I get close but not exact. I sense the events and locations I am trying to capture are just not entirely correct.
This is MS Dynamics GP 2010
0
Comment
Question by:rwheeler23
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:Steve Endow
ID: 38720480
Hi Richard,

It has been a while since I researched it and tested it, but I believe that the issue you are experiencing is due to the fact that you are trying to directly reference a field object (and field events) for a field in the LineScroll area.

My understanding is that VS Tools doesn't support field events in LineScroll areas.  It's one significant weakness in VS Tools.

It looks like you are limited to only the Line events.

LineFillBeforeOriginal
LineFillAfterOriginal
LineEnterBeforeOriginal
LineEnterAfterOriginal
LineChangeBeforeOriginal
LineChangeAfterOriginal
LineLeaveBeforeOriginal
LineLeaveAfterOriginal
LineInsertBeforeOriginal
LineInsertAfterOriginal
LineDeleteBeforeOriginal
LineDeleteAfterOriginal

The documentation says:  "To find out what data will be added to the current row of the scrolling window, examine the current row of the form-level table buffer for the table linked to the scrolling window."

I have probably been asked this question before, but I don't recall or don't know if there is a best practice for detecting field level events or field changes for a field on a scroll line.  It seems as if you have to do a before / after comparison for the whole line based on the line events.

One alternative is to avoid the scrolling window entirely by adding code to the Sales Item Detail Entry window, which has the Unit Price field in a standard window field, but I don't know if that will achieve the results you are looking for.

Let me know if this helps.  If you think of a different approach or find a different clue  you want to discuss, let me know.

Thanks,

Steve Endow
Dynamics GP Certified Trainer
Dynamics GP Certified IT Professional
0
 

Author Comment

by:rwheeler23
ID: 38720558
Steve, I kept experimenting and I believe I have come across with what will work.
I created an event for when the LocalUnitSellPrice changes and I call CheckForLineValueChanges which checks for a change on the line by using sopEntryWindow.LineScroll.IsChanged

So only if the Unit Sell Price was changed and then only by checking if there was a changed on the line do I then call my window prompting the user to confirm that they really want to change the sell price.

Please check this out and let me know what you think.



namespace GPCustomizations
{
    public class GPAddIn : IDexterityAddIn
    {
        // IDexterityAddIn interface
        public static string ApplicationName = "GP Miscellaneous Utilities";
        /* Setup SOP form so you can extract value off SOP_ENTRY form */
        static SopEntryForm sopEntryForm = Dynamics.Forms.SopEntry;
        static SopEntryForm.SopEntryWindow sopEntryWindow = sopEntryForm.SopEntry;

        /* Create a reference to the SOP Transaction Entry  screen */
        static frmSOPCheckSellPrice SOPCheckSellPriceForm;

        /* Set up SQL Connection Handler */
        private System.Data.SqlClient.SqlConnection DataConnection;

        /* Define the GP connection object */
        GPConnection GPConnObj;

        /* Create a stack trace flag for debugging purposes */
        static bool stackTraceWanted = true;

        public void Initialize()
        {
            /* Register a change event for the Unit Sell Price field of the Line Scroll window on the sales transaction entry window */
            sopEntryWindow.LineScroll.LocalUnitPrice.Change += new EventHandler(CheckForLineValueChanges);

        }

        /* Notify the user that the sell price has been changed and prompt for confirmation and reason */
        public void CheckForLineValueChanges(object sender, EventArgs e)
        {
            if (sopEntryWindow.LineScroll.IsChanged)
            {
                //sopEntryWindow.LineScroll.LocalUnitPrice.Change += new EventHandler(SellPriceChangeNotification);
                if (sopEntryWindow.LineScroll.LocalUnitPrice.Value != sopEntryWindow.LineScroll.UnitPrice)
                {
                    SellPriceChangeNotification();
                }
                SellPriceChangeNotification();
            }
            //SellPriceChangeNotification();
        }

        /* Notify the user that the sell price has been changed and prompt for confirmation and reason */
        public void SellPriceChangeNotification()
        {
            if (SOPCheckSellPriceForm == null)
            {
                SOPCheckSellPriceForm = new frmSOPCheckSellPrice();
            }
            else
            {
                if (SOPCheckSellPriceForm.Created == false)
                {
                    SOPCheckSellPriceForm = new frmSOPCheckSellPrice();
                }
            }

            /* Display notificaction that user has changed sell price */
            SOPCheckSellPriceForm.Show();
            SOPCheckSellPriceForm.Activate();
        }
    }
}
0
 
LVL 18

Accepted Solution

by:
Steve Endow earned 2000 total points
ID: 38721499
Hi Richard,

Does that code work?  I think the biggest question is whether the field changed event will fire.

sopEntryWindow.LineScroll.LocalUnitPrice.Change += new EventHandler(CheckForLineValueChanges);

I vaguely recall that such field level events do not work in a scrolling window for VS Tools, but please let me know if you are able to get it to work when editing multiple lines in the scrolling window.

And I also happened to notice this:

sopEntryWindow.LineScroll.LocalUnitPrice.Value != sopEntryWindow.LineScroll.UnitPrice

I think you will need to add ".Value" to the UnitPrice object.

Thanks,

Steve Endow
Dynamics GP Certified Trainer
Dynamics GP Certified IT Professional
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:rwheeler23
ID: 38721693
Steve, I have revised my code to what you see below. I believe the GP 2010 VS Toolkit does let you access fields in a Line Scroll because I am successful doing so.  The only problem I have left now is that my warning box form appears whenever the user changing the sell price, including when a new line is being added to the order. If I could just figure out how to stop that I would be golden. Any clue? So I only what the check to fire on existing lines, not new lines.

/* Check for line value change of the field LocalUnitPrice */
        public void CheckForLineValueChanges(object sender, EventArgs e)
        {
            LocalUnitSellPrice = sopEntryWindow.LineScroll.LocalUnitPrice.Value;
            UnitSellPrice = sopEntryWindow.LineScroll.UnitPrice.Value;

            sopEntryWindow.LineScroll.LocalUnitPrice.LeaveAfterOriginal += new EventHandler(SellPriceChangeNotification);
        }

        /* Notify the user that the sell price has been changed and prompt for confirmation and reason */
        public void SellPriceChangeNotification(object sender, EventArgs e)
        {
            if (SOPCheckSellPriceForm == null)
            {
                SOPCheckSellPriceForm = new frmSOPCheckSellPrice(LocalUnitSellPrice,UnitSellPrice);
            }
            else
            {
                if (SOPCheckSellPriceForm.Created == false)
                {
                    SOPCheckSellPriceForm = new frmSOPCheckSellPrice(LocalUnitSellPrice,UnitSellPrice);
                }
            }

            /* Display notificaction that user has changed sell price */      
            SOPCheckSellPriceForm.Show();
            SOPCheckSellPriceForm.Activate();
        }
0
 

Author Comment

by:rwheeler23
ID: 38722162
Steve, I think I have finally got this straight. In the SellPriceChangeNotification routine I added two checks.

1) A check of the line scroll record to see if it exists in the SOp10200 table. I do not want the check performed if this is a new likne detail record
2) Check the line scroll value of UnitSellPrice against the actual value in the SOP10200 table.

I have attached the code for your review. If this looks good to you please feel free to use it for any of your clients.
GPCode.txt
0
 

Author Closing Comment

by:rwheeler23
ID: 38725666
Thnaks for helping me think this through.
0
 
LVL 18

Expert Comment

by:Steve Endow
ID: 38725815
Thanks for the update.

So I guess I was wrong about the field level events.  I thought that there was some limitation with VS Tools and scrolling windows--maybe it has to do with navigating lines or inserting new lines.

Glad you got it working.

Thanks,

Steve Endow
Dynamics GP Certified Trainer
Dynamics GP Certified IT Professional
0
 

Author Comment

by:rwheeler23
ID: 38725836
It was not easy. A lot of trial and error. By the way, I just submitted another question regarding this project. I do not know if you can find it so if not let me know and I will send it via email.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part III
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question