Archives

Archives / 2020 / May
  • How to get user friendly error message out of WebException

    Hello everybody,

    today I want to leave a short notice on how to get user friendly text of WebException. Imagine that you need to know which part of data in your json is missing. How can you quickly figure out which part? For one of my projects I wanted to get easy way of saying user which field is potentially missing. In order to achieve that I've used following fragment:

    catch (WebException ex)

    {

      string errorMessage = string.Empty;

      if (ex.Response != null)

      {

          using (var errorResponse = (HttpWebResponse) ex.Response)

          {

              using (var reader = new StreamReader(errorResponse.GetResponseStream()))

              {

                  errorMessage = reader.ReadToEnd();

       … more

  • Why code changes from dll are not shown on the form in Acumatica

    Hello everybody,

    today I want to share with you interesting use case which stolen one night of sleep from me, as well as from one of my collegues. 

    We had very trivial case. Or at least we thought it is trivial. In Acumatica we had something like this:

    #region UsrCardTheme

    [PXDBString(256)]

    [PXUIField(DisplayName="Card Theme")]

    public virtual string UsrCardTheme { get; set; }

    public abstract class usrCardTheme : PX.Data.BQL.BqlString.Field<usrCardTheme> { }

    #endregion

    For some reason we weren't able to update it in database, so we've made changes to it like this in order to check if we will see it in UI:

    #region UsrCardTheme

    [PXDBString(256)]

    [PXUIField(DisplayName="Card  … more

  • How to call non public method of Acumatica

    Hello everybody,

    today I want to share with you how it's possible to call some methods of Acumatica, which are not public, and which you don't want to copy/paste completely into your source code. In that case reflection will save you. Consider calling of InsertSOAdjustments method of graph SOOrderEntry below.

    MethodInfo invokeSOAdjustment = typeof(SOOrderEntry).GetMethod(

        "InsertSOAdjustments", BindingFlags.Instance | BindingFlags.NonPublic, Type.DefaultBinder,

        new[] { typeof(SOOrder), typeof(ARPaymentEntry), typeof(ARPayment) }, null);

    invokeSOAdjustment.Invoke(Base, new object[] { order, docgraph, payment });

    Also I want to give you a word of warning, that such approach … more

  • How to avoid navigation away from created item after calling PressSave or Persist action

    Hello everybody,

    today I want to tell you a story, that swallowed quite big amount of time of whole team.

    Recently we've got seemingly easy to fulfil requirement: 

    Add button to the grid

    Inside of the button fullfil 

    Persist

    Call to db with modifications

    Persist one more time

    Leave the page opened on created item in UI

    Initially our code looked like this:

    public PXAction<SOOrder> SomeAction;

    [PXButton(CommitChanges = true)]

    [PXUIField(DisplayName = "Some Action", Visible = true)]

    protected virtual IEnumerable someAction(PXAdapter adapter)

    {

        Base.Actions.PressSave();

        //API call

        Base.Actions.PressSave();

        return adapter.Get();

    }

    I could say that … more

  • Template for usage of PXLineNbr attribute in Acumatica

    Hello everybody,

    today I want to leave a note on how to use PXLineNbr attribute in Acumatica pages. Recently myself and one of my team members struggled a bit with a question on how to add it properly. Below goes a bit changed worked tempalte:

    public class PrimaryTable : IBqlTable

    {

        #region LineId

        public abstract class lineId : PX.Data.BQL.BqlInt.Field<lineId> { }

        [PXDBInt]

        [PXDefault(0)]

        public virtual int? LineId { get; set; }

        #endregion

        #region LineCntr

        public abstract class lineCntr : PX.Data.BQL.BqlInt.Field<lineCntr> { }

        [PXDBInt]

        [PXDefault(0)]

        public virtual int? LineCntr { get; set; }

        #endregion

    }

    public  … more

  • How to override BuildTAxRequest method of APInvoiceEntryExternalTax class

    Hello everybody,

    today I want to leave a short techy post on how to override method BuildTaxRequest of APInvoiceEntryExternalTax class.

    public class APInvoiceEntryExternalTaxExt: PXGraphExtension<APInvoiceEntryExternalTax, APInvoiceEntry>

    {

        [PXOverride]

        protected virtual GetTaxRequest BuildTaxRequest(APInvoice invoice, Func<APInvoice, GetTaxRequest> baseAction)

        {

            var result = baseAction(invoice);

            //Your code

            return result;

        }

    }

    Reason for such a behavior is a fact that class APInvoiceEntryExternalTax is graph extension for graph. That's why such a construction is needed.

    more

  • How to override the Persist method properly

    Hello everybody,

    today I want to write a few words on how to override persist method of Acumatica properly. When I say properly I mean not save just some fragment of data, but use transaction like approach.

    In other words how to achieve all or noghint during persisting.

    Quite often I see template like this:

    public void Method1()

    {

        //normal flow

    }

    string message = "Forbidden to do anything at 18 hour";

    public void Method2()

    {

        if (DateTime.Now.Hour == 18)

        {

            throw new PXException(message);

        }

    }

    public void RollBackMethod1AndMethod2()

    {

    }

    [PXOverride]

    public void Persist(Action del)

    {

        try

        {

            del();

            Method1(); … more