Blog

Here I document some issues for searching of which I spent more then 15 minutes

  • 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

  • Why Acumatica can't restore snapshot bigger then 2Gb?

    Hello everybody,

    today I want to share with you my guess regarding why Acumatica can't restore snapshot bigger then 2 Gb. As far as I see at database level, all files are going into table UploadFileRevision. If to look into structure of this table, you'll find that it has column data, which looks like this: 

    if to google a bit, you'll find that maximum size which Varbinary(MAX) can accomodate is 2 Gb. 

    That's why if you snapshot is bigger then 2 Gb, look for other way of restoring of your snapshot

    Summary

    As of now it is my guess on why snapshot can't be restored. I'll update everybody how to deal with this, once I'll find solution, which satisfies me completely. more

  • Gross income and net income

    Hello everybody,

    today I want to leave a note on gross income and net income from two standpoints: business and employee.

    Gross income = Total sales - Cost of goods sold

    Net Income = Total sales - Cost of goods sold - Selling expenses. 

    Because Gross income = Total sales - Cost of goods sold quite often Net income is recorded in this form:

    Net Income = Gross income - Selling expenses

    If some business had 1 000 000 $ sales and cost of goods sold is 600 000 $ and selling expenses are 250 000 then

    Gross income = 1 000 000 - 600 000 = 400 000

    Net Income = 400 000 - 250 000 = 150 000

    But if you are an employee, then for you differnet definitions are applied.

    Gross income = all salary … more

  • How to implement PXStringListAttribute in Acumatica

    Hello,

    today I want to leave a post about code quality regarding of PXStringListAttribute. If to look in older versions of Acumatica manuals ( for example T200 manual ) you can see something like this:

    public class Something : IBqlTable

    {

        [PXStringList(

            new string[]

            {

                ShipmentTypes.CollectorNew,

                ShipmentTypes.CollectorSent,

                ShipmentTypes.CollectorResponded,

                ShipmentTypes.CollectorExpired

            },

            new string[]

            {

                "New",

                "Sent",

                "Responded",

                "Expired"

            })]

        [PXString]

        public virtual string Field { get; set; }

    }

    Recommended … more

General information

Greetings! Here I publish everything I found useful or beneficial for me and maybe others. For some sql samples I'm using wiseowl samples. 

Contact information

If you want to contact me more on any subject printed at this web stie, you can email me: zaljur1989(at)gmail.com

Job information

If to speak in general, I'm developer. For now I work as Solutions Architect in company Kensium.