Thursday, 19 April 2018

Resort grid rows with Drag & Drop grid rows

Hi Everyone,

In Acumatica 2018R1 we have a new cool feature to drag and drops rows of the grid to resort them.
As you can see sorting is still based on database column (In my case it is Sort Order) but Acumatica can automatically reorder all rows based position you dropped it.
This is just a first version so still have some limitations (like it is still not fully works with extensions for existing DACs), but I really like we can  bring new and very friendly user experience to ERP.

How to implement it in own code? To have this feature you need to change several things in your Graph, DAC and Page:

In Graph we need to replace your normal PXSelect with new PXOrderedSelect. This data view has all logic to update sorting upon drop of the row.

public PXOrderedSelect<AAMasterAADetail
      OrderBy<Asc<AADetail.masterIDAsc<AADetail.sortOrder>>>> DetailsView;

Also PXOrderedSelect will add 2 new buttons (PastRow and ResetOrder) to graph actions that you may need to hide from Datasource actions later in the page.

In the DAC you need to implement interface ISortOrder, that requires to have LineNbr and SortOrder properties.
  public class AADetail IBqlTableISortOrder
    #region LineNbr
    [PXDBInt(IsKey true)]
    [PXUIField(DisplayName "Line Nbr"Visible false)]
    public virtual intLineNbr getset}
    public abstract class lineNbr IBqlField }
    #region SortOrder
    [PXUIField(DisplayName "Sort Order"Visible falseEnabled false)]
    public virtual intSortOrder getset}
    public abstract class sortOrder IBqlField }

In the page you need to do several things: hide actions, allow grid Drag&Drop and configure postback.

Here in data-source you need to hide commands:
<px:PXDataSource ... >
  <px:PXDSCallbackCommand Name="PasteLine" Visible="False" 
   DependOnGrid="grid" CommitChanges="true" />
  <px:PXDSCallbackCommand Name="ResetOrder" Visible="False" 
   DependOnGrid="grid" CommitChanges="true" />

Here in grid you need to sync grid position, allow drag and drop and link PasteCommand with action.
<px:PXGrid SyncPosition="True" ID="grid" ... >
 <Mode InitNewRow="True" AllowDragRows="True" ></Mode>
 <CallbackCommands PasteCommand="PasteLine">
  <Save PostData="Container" />

After this drag and drop should work as it shown on the grid before!

Hope it is helpful for you! Have a nice development!

Thursday, 12 April 2018

PXSelector and DirtyRead

Hi Everyone,

Want to speak today about Dirty Read property of selector.
Base explanation you can find in Acumatica API reference. How ever this one is very basic, so let me try to share with you real case.

You may know about Readonly vs Merged data retrial from DataView. Basically if you use PXSelectReadonly data-view it will always return data only stored in database. If you use standard data-view like PXSelect Acumatica will get data from DB and than merge it with unsaved data from cache.
This is fully applicable for data-views (PXSelect, PXSelectReadonly) and selectors as well. When you define PXSelectorAttribute than it will be always read-only by default. However you can make it not read-only using DirtyRead = true parameter.

[PXSelector(typeof(Users.pKID), SubstituteKey = typeof(Users.username), DirtyRead = true)]
protected virtual void Contact_UserID_CacheAttached(PXCache cache)

Why you may need it? Lets imagine you have 2 DACs that are refers each other thought text key with PXSelectorAttribute.
In this case if you insert new record for DAC 1 and DAC 2 simultaneously you will may have a problem with selector as record of DAC 1 is not yet saved and selector will throw Item not Found exception.
Here exactly DirtyRead comes to help us - in this scenrarion selector with DirtyRead=true will select DAC1 from database, merge it with cache (new inserted record) and no error will be triggered.

In the example of PXSelector above Acumatica allows to link Contact with just created use account. So that means that if you create user on the fly with code and it is not saved but needs to be linked with contact - DirtyRead helps us.

Profit! Hope it helps!

Monday, 2 April 2018

Schedule Database Maintenace

Hi All,

Just want to share one screenshot guide on how to schedule a database maintenance:
Acumatica Database Maintenance

Have a smooth maintenance!