Solved

MS Dynamics GP VS # capture event

Posted on 2012-12-24
8
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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