Skip to main content

Notifications

Microsoft Dynamics GP (Archived)

Visual Studio C# GP 2015 R2 Capture Action Button Events

Posted on by 75,730

I am trying to capture the event when a user goes to the Sales Transsction entry screen, clicks on Actions and then Tranasfer. I want to capture the event of clicking on transfer. I have this set of code but what happens is the message in this code pops up when the SOP screen opens or jst about any other clicks on the screen. I only want to capture the even when Transfer is clicked.  How should this code be changed?

/* Register a click event for the Actions->Transfer click */
try
{
    sopEntryForm.SopEntry.ActionButton.Change += new EventHandler(ActionButton_Change);                
}
catch (Exception ex)
{
    string eMsg = "004: ERROR: " + ex.Message;
    if (stackTraceWanted) eMsg += "\n" + ex.StackTrace;
    MessageBox.Show(eMsg);
}

/* Method to handle Action Button change event */
private void ActionButton_Change(object sender, EventArgs e)
{
    switch (sopEntryForm.SopEntry.ActionButton.Value)
    {
        case 0: MessageBox.Show("I clicked Transfer");
            break;

case 1:             MessageBox.Show("I clicked something else");             break;
        default:             MessageBox.Show("I think, therefore I am! " + sopEntryForm.SopEntry.ActionButton.Value.ToString());             break;     } }

*This post is locked for comments

  • WCL Profile Picture
    WCL 140 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    Old thread but thought I'd add this for anyone coming across it:

    looks like Richared was trying to use his old Change handler when testing code hooked on ValidateBeforeOriginal  - but the event args are different for the Validate handle - needs CancelEventArgs rather than EventArgs.  So I suspect that s why it wasn't firing as expected.

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    sopEntryForm.SopEntry.ActionButton.EnterAfterOriginal += new EventHandler(ActionButton_Change); is the event that I found would work. Validate After Original did nothing. One curious thing though is when my window pops up and the user does what is needed and clicks edit they are back on the SOP Transaction Entry screen not on the transfer screen. If they click Transfer a second time they do not get my window they get the Transfer screen. This is tolerable but I am not quite sure why it is working this way.

  • Tim Wappat Profile Picture
    Tim Wappat 5,701 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    Thanks Vaidy - couldn't have put it better myself.

  • Suggested answer
    Vaidy Mohan Profile Picture
    Vaidy Mohan 351 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    EnterAfterOriginal event is triggered when the focus shifts to that particular field, in your case "Action Button". ValidateAfterOriginal event is trigger after the actual clicking action is performed.

    To test this, you may simply use TAB key till you reach "Action Button". The moment "Action Button" is highlighted, EnterAfterOriginal event would get triggered. ValidateAfterOriginal would be triggered only after you click/select any of the options under the "Action Button".

    Hope that helps.

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    This also appears to work. What is the difference between EnterAfterOriginal and ValidateAfterOriginal?

    ===========================================================================
                /* Register a click event for the Actions->Transfer click */
                try
                {
                    sopEntryForm.SopEntry.ActionButton.EnterAfterOriginal += new EventHandler(ActionButton_Change);                
                }
                catch (Exception ex)
                {
                    string eMsg = "004: ERROR: " + ex.Message;
                    if (stackTraceWanted) eMsg += "\n" + ex.StackTrace;
                    MessageBox.Show(eMsg);
                }

    =============================================================
            /* Method to handle Action Button change event */
            private void ActionButton_Change(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(sopEntryForm.SopEntry.SopNumber) && sopEntryForm.SopEntry.SopType == 2 )
                {
                    switch (sopEntryForm.SopEntry.ActionButton.Value)
                    {
                        case 0: MessageBox.Show("I clicked Transfer");
                            break;
                        case 1:
                            MessageBox.Show("I clicked something else");
                            break;
                        default:
                            MessageBox.Show("I think, therefore I am! " + sopEntryForm.SopEntry.ActionButton.Value.ToString());
                            break;
                    }
                }
            }

  • Verified answer
    Tim Wappat Profile Picture
    Tim Wappat 5,701 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    WOMM

    2017_2D00_05_2D00_04_5F00_23_2D00_55_2D00_23.jpg

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    sopEntryForm.SopEntry.ActionButton.validatebeforeoriginal += new EventHandler(ActionButton_Change); is not valid. But I will try looking for a document number and type.

  • Tim Wappat Profile Picture
    Tim Wappat 5,701 on at
    RE: Visual Studio C# GP 2015 R2 Capture Action Button Events

    Should you not be hooking into the ActionButton validatebeforeoriginal event rather than change.

    Also need to check your have a document loaded and that it is the document type you expect to work with (invoice/order/quote etc).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans