How to save the Change Orders screen automatically

38 views Asked by At

I appreciate the help in advance, I am trying to automatically save the information on the "Change Orders" screen. When they press the "Create Change Order" button on the "Change Request" screen.

Could you tell me what event or method I should use to achieve this.

enter image description here

enter image description here

2

There are 2 answers

1
Amit Ranjan On

You have two options. 1.Write code to create a ChangeOrder in RowPersisted Event of ChangeRequests 2. You can override the existing Create Change Order button.

0
Zoltan Febert On

You can override CreateChangeOrder method. Base method throws a PXRedirectRequiredException, and if you catch it, you can extract ChangeOrderEntry graph from it and you can call the Save function.

using System;
using System.Collections;
using PX.Data;
using PX.Objects.PM;
using PX.Objects.PM.ChangeRequest;

namespace PX.Objects.PM.Extensions
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class ChangeRequestEntryExt : PXGraphExtension<ChangeRequestEntry>
    {
        [PXOverride]
        public virtual IEnumerable CreateChangeOrder(PXAdapter adapter, 
            Func<PXAdapter, IEnumerable> baseMethod)
        {
            try
            {
                // Call base method, a PXRedirectRequired exception will be raised there
                return baseMethod.Invoke(adapter);
            }
            catch (PXRedirectRequiredException e)
            {
                // Catch the exception, get the Graph from it, and press Save
                try
                {
                    ((ChangeOrderEntry)e.Graph).Save.Press();
                }
                catch (Exception saveException)
                {
                    // We don't need to handle the exception here, we just need to catch it and open the graph anyway.
                }
                // Rethrow PXRedirectRequired exception, this will open the new Change order
                throw;
            }
        }
    }
}