Search code examples
c#controllerxaf

related to question: show message after a successful record saving


I have been read the answer for the question written in the following link: Show message after a successful record saving

The solution was very useful, but my question is: If I want to show a message only after a new object is saved, and hide it in other record saving cases, How to do that?


Solution

  • You could do something like the below. If the event is not the event type you are looking for, you just don't set the message. And if the message is null or empty, you don't show it.

    void ObjectSpace_Committed(object sender, EventArgs e)
    {
        if (!string.IsNullOrEMpty(message))
        {
            MessageOptions options = new();
            options.Duration = 2000;
            options.Message = message;
            options.Type = InformationType.Success;
            options.Web.Position = InformationPosition.Right;
            options.Win.Caption = "Success";
            options.Win.Type = WinMessageType.Toast;
            Application.ShowViewStrategy.ShowMessage(options);
            message = string.Empty;
        }
    }
    
    void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
    {
        if (ObjectSpace.IsNewObject(e.Object))
        {
            message=string.Format("Record Saved Successfully");
        }
    }