web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

VST: Cancelling a SaveRecord?

(0) ShareShare
ReportReport
Posted on by 225

Hi:

I was looking at this post by David Musgrave and was hoping someone could help clarify something.

I find myself needing to cancel a SaveRecord for a third party addon based on whether my extra data has been filled in. I implemented the ...SaveRecord.InvokeBeforeOriginal handler and tried "flipping" the only boolean out parameter in the SaveRecordProcedure.InvokeEventArgs object thinking that it would stop the procedure. It didn't.

Am I right in thinking that everyone simply names the script "SaveRecord" as a convention or does Dexterity or GP enforce it as part of some sort of framework? I am simply trying to understand if this is a bug in the third party addin or whether I should have no such expectation.

If I shouldn't expect the SaveRecord approach to work, can I accomplish what I want using the VBA approach (still in VST)? I tried briefly, but was surprised to find that the Bridge.AfterModalDialogEventArgs.Response property is read only so I can't override the user's response. Am I missing anything?

To be clear, I don't have any Dexterity experience. I started my GP journey with a first VBA customization and am now working on my a VST addin.

Thanks!
Paul

*This post is locked for comments

I have the same question (0)
  • Tim Wappat Profile Picture
    5,703 on at
    RE: VST: Cancelling a SaveRecord?

    Paul,

    Naming is by convention as far as I am aware.

    The ComponentModel.CancelEventArgs should have a cancel property, so settings e.cancel on the EventArgs is how I'd do it. If that fails, then it may be time to contact the authors of the 3rd party product.

    If there is a UI button that starts the save, then investigate that, but as David's post shows, some windows have multiple ways to cause a save. You may be lucky and find for this example there is only one way.

    Tim.

  • Pablito Profile Picture
    225 on at
    RE: VST: Cancelling a SaveRecord?

    Thanks for the reply Tim! I really appreciate it.

    Yes, the ComponentModel.CancelEventArgs is indeed present on the Save button click event and that works fine. I can cancel it without a problem if needed. My problem is with the other ways to cause a save remains.

    Since my post, I have looked at the "VBA approach" more closely. As per the article, I tried registering for the MaintWindow_AfterModalDialog and it does fire. The problem is that the AfterModalDialogEventArgs.Response property is read-only for me in VST. Though I can react to the user's selection, I cannot override the user's response and so cancel the save if needed. Not good.

    I've since noticed that the MaintWindow_BeforeModalDialog event's Response property IS read/write. I'm thinking that I should be able to implement that event handler and simply ask the user myself before the "actual" modal dialog is displayed. The problem in doing that though is that I'm putting myself in a recursive situation as the event will trigger again for my own dialog, etc., etc. In short, I'll have to do it very carefully, but it should work.

    I really wish I could have used the SaveRecord approach. It would have been much cleaner.

    Anyway, thanks again for the response.

    Paul

  • Peter Muchira Profile Picture
    1,912 on at
    RE: VST: Cancelling a SaveRecord?

    Hello Pablito,
    Did you get any headway with the SaveRecord on VST? Am having a similar issue.

  • Verified answer
    Almas Mahfooz Profile Picture
    11,009 User Group Leader on at
    RE: VST: Cancelling a SaveRecord?

    This is a very good post and I really like to read these types of discussion. Although I am very willing to work on VSTools but never ever got a time off from my dexterity developments. :-(

    I want to say few things in regard of how dexterity developers handle these situation, So maybe people will know it's not an efforless job we do (unrespected, not so cool dexterity developers).

     

    It's just convention that everyone simply names the script "SaveRecord", and it's not any sort of framework to save records. You can find them in various GP window and each one specifically work for the related window. But not necessacry they do the save operation, they may be calling some other script which is exactlly responsible for saving a record. For Example on Purchase oreder Entry window there is only SaveButton and SaveButtonA no SaveRecord.

    For Example Transaction Entry window, It's the local dummy save button responsible for doing the real work.

    GLSave4.png 

    GLSave4.png

     

    I usually don't use these button events when need to save additional data in custom table, as once we pressed the save button we can not make sanscript to stop, it will complete its job (either save or give message).

    So if we save records in our table before save button/save record change event , and because of any reasone record don't get saved in GP table then by the time our data already get saved with new record in custom table. Let say user instead of saving the new item decided to cancle it and close the window.

    In this way I always prefer to use table trigger, so when record gets saved or update then only my script will call and copy records in custom table.

    l_result = Trigger_RegisterDatabase(anonymous(table IV_Item_MSTR),
    form IV_Item_Maintenance,TRIGGER_ON_DB_ADD+TRIGGER_ON_DB_UPDATE, script IV_DB_AddUpdate);
    if l_result <> SY_NOERR then
    	warning "Database add/update trigger registration failed.";
    end if;


    I don't find any table events equivalent to TRIGGER_ON_DB_ADD  or TRIGGER_ON_DB_UPDATE on VSTools AddHandler and it seems it only provide events for Forms. Am I right?

     

    Sometimes when DB trigger don't work for any reason for any window (things like this happened in dexterity), we do extra coding like creating one global script whcih checks GP table for record and if no record find in GP table then will also delete the respective record from our custom table, and call that script from possible events.

  • Tim Wappat Profile Picture
    5,703 on at
    RE: VST: Cancelling a SaveRecord?

    Almas,

    I enjoyed reading your post, nice to get a "not so cool" perspective on this, a great contribution to the thread.

    Indeed it would be good to have database triggers in VST.

    Thanks

    Tim.

  • Peter Muchira Profile Picture
    1,912 on at
    RE: VST: Cancelling a SaveRecord?

    Hi Paul,

    I have just tried to use the ComponentModel on a window that has the 'SaveRecord' field (Payables Transaction Entry). I have set a condition that the 'PO Number' field in the PM Entry should not be blank. The 'cancel' boolean is successfully preventing the record from being saved - whether triggered by clicking the 'save' button, or even by trying to close the window. I used the following line (Vb.Net):

    saveRecord.PNG

  • Pablito Profile Picture
    225 on at
    RE: VST: Cancelling a SaveRecord?

    Oh my! There has been quite a bit of activity here while I was asleep.

    Peter: It looks like you've solved your problem. Congrats! In my case, there really wasn't any cancel-able SaveRecord event I could register against.

    For others that may follow, what I've managed to deduce is that the DAG generates form and window objects in a fairly consistent manner, but the methods, events and properties obviously depends on the Dexterity implementer. Taking your PmTransactionEntry as an example, I can get hold of the form itself via the Microsoft.Dexterity.Applications.Dynamics.Forms.PmTransactionEntry reference. The consistent bits under each such form is the presence of the following standard object references:

    • Commands
    • Functions
    • Procedures
    • Tables

    Again, the contents of each of these objects depends on the Dexterity implementer. In addition, the form object contains an object reference to each of the Windows owned by the form. In the case of the PmTransactionEntry, the main window appears to also be called by the same name; so: Microsoft.Dexterity.Applications.Dynamics.Forms.PmTransactionEntry.PmTransactionEntry. This window does have a SaveRecord event handler with a ComponentModel.CancelEventArgs parameter whereas my 3rd party Window does not. However, it did have a SaveRecord event handler under the Procedures object at the form level mentioned above, but without the ComponentModel.CancelEventArgs parameter. This is what I was trying but failing to use.

    I ended up implementing this as I described in my second post. I register for both the "before" and "after" events for both the SaveButton and the ModalDialog handlers. The "before" events are used to validate that everything is as I need it to be before I allow the save operation to go through. By the time the "after" event is triggered, I know that the application MAY have already done its thing and saved some data. I say MAY because I've found that the event has been fired even when the Dexterity script had failed the request for some reason (e.g. mandatory field not filled in). As I didn't want to save my data in such a situation, I was forced to physically check the database to see if the Save operation had actually completed. This is certainly not as elegant as I'd like it to be.

    Almas: I had somewhat arrived at the same conclusion about the SaveRecord as it isn't present consistently as you point out. That said, it is good to get the confirmation from a Dexterity developer. Thanks!

    I am curious about your comment: "... as once we pressed the save button we can not make sanscript to stop...". Can you elaborate? This sounds to be what I am observing above.

    Based on my limited experience so far, I had rather been assuming that the DAG tool used to generate the bridge DLLs auto-magically identifying the various... I'll go with the term "public Dexterity script artifacts" (until I know better) and insert pre and post events appropriate to the type of artefact (text control, window, form, etc). When the ComponentModel.CancelEventArgs is present in the generated event handler (not sure what decides this in the DAG), it seems to consistently work. Not so otherwise.

    My simplistic view of the world is far from complete as I know very little about how Dexterity works. When I have time, I'd like to read through some of the Dexterity documentation to get my head around the basics. I'm convinced that some of the VBA and VST limitations will make sense then. If you can shed any light in that direction, that would be awesome.

    The table triggers functionality you mention is interesting. This idea came up with a colleague when we thought we might need to delete our custom data entry after the fact... as you describe in your last paragraph. However, in our case we thought to add the trigger straight in SQL Server.

    So your triggers are in Dexterity? And when you register for an Add or an Update, you still have the context of the relevant form or window? That functionality would certainly be nice. No, I haven't found anything of the kind in VST. Table objects relevant to the form are consistently located under the Tables object in the DAG generated form object (see above), but there don't appear to be any register-able events.

    Anyway, good discussion all! Sorry for my long winded reply, but I figure I may need to refer back to my own findings at a later time. :)

    Paul

  • Almas Mahfooz Profile Picture
    11,009 User Group Leader on at
    RE: VST: Cancelling a SaveRecord?

    Paul,

    I am not good in explaining things but let me try. :-)

    >>>>I am curious about your comment: "..."as once we pressed the save button we can not make sanscript to stop...". Can you elaborate?

    For your question, I have found a very good situation, which explains my comment, see below.

    https://community.dynamics.com/gp/f/32/p/154659/361451#361451

     

    Regardsing SQL triggers, we usually try to avoid it as it creates issues, but it's not that we don't use it. But one has to be carefully on using sql triggers. Yes we use lots of triggers as our all development based on it, we have all sorts of triggers.
     

  • Tanuja Patel Profile Picture
    140 on at
    RE: VST: Cancelling a SaveRecord?

    Hi Almas Mahfooz,

    I have added one custom filed on form Tax_Detail_Maintenance. Now I want to save the record in my custom table with this field while clicking on Save button of form Tax_Detail_Maintenance.

    But it is not work. Even though when I wrote the script on Save Button or Save Record or DB trigger. It is not run. Do you have any idea how to use dexterity code in this case.

    Thanks,

    Tanuja

  • Tanuja Patel Profile Picture
    140 on at
    RE: VST: Cancelling a SaveRecord?

    Hi Almas Mahfooz,

    I have added one custom filed on form Tax_Detail_Maintenance. Now I want to save the record in my custom table with this field while clicking on Save button of form Tax_Detail_Maintenance.

    But it is not work. Even though when I wrote the script on Save Button or Save Record or DB trigger. It is not run. Do you have any idea how to use dexterity code in this case.

    Thanks,

    Tanuja

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans