Solved

MS Dynamics GP VS # capture event

Posted on 2012-12-24
8
659 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 500 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now