Acumatica and ObjectsEqual lack of parameters

Hello everybody,

today I want to share how I deal with ObjectsEqual limitation. In one of my tasks I had requirement to check for equality more then eight parameters and found that ObjectsEqual takes only 8 parameters. But I needed more. 

In order to fix it I decided to use extension classes of C# which allows inject into existing class new functionality.

Here is the way how I did it:

public static class PXCacheExtensions
    {
        public static bool ObjectsEqualExt(this PXCache cache, object a, object b, params IBqlField[] values)
        {
            var result = true;
            foreach (var bqlField in values)
            {
                result = result && object.Equals(cache.GetValue<IBqlField>(a), cache.GetValue<IBqlField>(b));
            }

            return result;
        }

        public static bool ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9>(this PXCache cache, object a, object b)
            where Field1 : IBqlField
            where Field2 : IBqlField
            where Field3 : IBqlField
            where Field4 : IBqlField
            where Field5 : IBqlField
            where Field6 : IBqlField
            where Field7 : IBqlField
            where Field8 : IBqlField
            where Field9 : IBqlField
        {
            return (cache.ObjectsEqual<Field9>(a, b) && cache.ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8>(a, b));
        }

        public static bool ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10>(this PXCache cache, object a, object b)
            where Field1 : IBqlField
            where Field2 : IBqlField
            where Field3 : IBqlField
            where Field4 : IBqlField
            where Field5 : IBqlField
            where Field6 : IBqlField
            where Field7 : IBqlField
            where Field8 : IBqlField
            where Field9 : IBqlField
            where Field10 : IBqlField
        {
            return (cache.ObjectsEqual<Field10>(a, b) && cache.ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9>(a, b));
        }

        public static bool ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11>(this PXCache cache, object a, object b)
            where Field1 : IBqlField
            where Field2 : IBqlField
            where Field3 : IBqlField
            where Field4 : IBqlField
            where Field5 : IBqlField
            where Field6 : IBqlField
            where Field7 : IBqlField
            where Field8 : IBqlField
            where Field9 : IBqlField
            where Field10 : IBqlField
            where Field11 : IBqlField
        {
            return (cache.ObjectsEqual<Field11>(a, b) && cache.ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10>(a, b));
        }

        public static bool ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11, Field12>(this PXCache cache, object a, object b)
            where Field1 : IBqlField
            where Field2 : IBqlField
            where Field3 : IBqlField
            where Field4 : IBqlField
            where Field5 : IBqlField
            where Field6 : IBqlField
            where Field7 : IBqlField
            where Field8 : IBqlField
            where Field9 : IBqlField
            where Field10 : IBqlField
            where Field11 : IBqlField
            where Field12 : IBqlField
        {
            return (cache.ObjectsEqual<Field12>(a, b) && cache.ObjectsEqual<Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11>(a, b));
        }


    }

After those modifications my cache accepts twelve parameters for comparing

Enums and strings

Hello everybody,

I want to share some pieces of code how to work with enums. 

Some time it is needed to have list of string constants in your code, which can feet to some strings with spaces. 

enum EarningType
    {
        [Description("Virginina")]
        VL,
        [Description("Salt and Lasso")]
        SL,
        [Description("TO")]
        TO,
        [Description("RG")]
        RG
    }

One of easy ways to use description is usage of extension methods like this:

 public static class EnumsProcessor
    {
        public static string GetEnumDescription(this Enum value)
        {
            var fi = value.GetType().GetField(value.ToString());

            var attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes.Length > 0)
                return attributes[0].Description;
            return value.ToString();
        }
}

and then in code you can write something like this:

EarningType.VL.GetEnumDescription() which will return you description from description field.

Execute stored procedure in Acumatica

Hello everybody.

I want to share if you need to execute stored procedure in Acumatica how to achieve it. 

It's simple.

1. Create Stored procedure in db.

2. Use in your code PXDatabase.Execute.

For example let's say you created stored procedure which has name DeletePrTranByPrPayrollAndPayrollDetailsId and takes as parameters @prPayrollRefNbr and @prPayrollDetailsID which are of type nvarchar.

Then you can call stored procedure in the following way:

var pars = new List<PXSPParameter>();

PXSPParameter p1 = new PXSPInParameter("@prPayrollRefNbr", PXDbType.NChar, details.PayrollRefNbr);

PXSPParameter p2 = new PXSPInParameter("@prPayrollDetailsID", PXDbType.NChar, details.PRPayrollDetailID);

pars.Add(p1);

pars.Add(p2);

PXDatabase.Execute("DeletePrTranByPrPayrollAndPayrollDetailsId", pars.ToArray());

PXSelect vs PXSelectReadonly

Hello everybody,

today I want to share with you important difference between PXSelect  and PXSelectReadonly.

In my project I had the following situation. PXSelect of table name didn't give me what actually was in db. After a long research I found PXSelectReadonly and key difference is that PXSelectReadonly reads directly from db without usage of Acumatica Cache. 

RowPersisting declaration in Acumatica

Just small search result.

Row persiting event declares as following:

protected virtual void YourDACClasss_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)

   {

 

   }

Create new instance of graph in Acumatica

Hello,

today I want to note how to create new instance of Graph. Lets say you need to create instance of graph PRPaySlipManager.

In that case you can get instance of that graph in the following way:

PRPaySlipManager manager = PXGraph.CreateInstance<PRPaySlipManager>();

What is tstamp

Hello everybody,

I want to share what is purpose of field TStamp in database for tables in Acumatica. In reality you can make projects without it, but. If you add it, you'll help Acumatica with concurency management

RowInserting and RowInserted difference in Acumatica

Hello everybody,

now I want to share with you difference between RowInserting and RowInserted events.

The RowInserting event happens before the new data record is actually inserted into the cache but after all field events happen for this data record. The RowInserted event happens after the actual insertion. If you change the data fields of the data record that you insert in a RowInserting event handler, no field events will be raised for these data fields. You use the RowInserted event to do something after a data record is inserted into the cache. For example, you can use a RowInserted event handler of the master data record to add a default detail data record.

Sample of RowInserting:

protected virtual void APAdjust_RowInserting(PXCache sender, PXRowInsertingEventArgs e)

{

.................. 

}

Sample of RowInserted

protected virtual void APAdjust_RowInserted(PXCache sender, PXRowInsertedEventArgs e)

{

.................. 

}

The main purpose of RowInserted IMHO is to add default details to data record

How to add buttons Refresh Add Row, Delete Row, Fit To Screen in Grid of Acumatica

Hello everybody,

Imagine that you crated in your page Grid, and when opened it at page can't notice buttons Refresh Add Row, Delete Row, Fit To Screen in Grid. I believe it can be puzzling how to add those buttons to screen as it was for me at once.  Add to your grid following line:

 SkinID="Details"

For example it can look like this:

<px:PXGrid ID="PXGrid1" runat="server" DataSourceID="ds" TabIndex="-8036" AdjustPageSize="Auto" AllowPaging="True" Height="200px" Width="100%" SkinID="Details" KeepPosition="True" MatrixMode="True"  SyncPosition="True">

If you add those attributes, you'll see those buttons.