A quick tip for today. You can check the state of an object by using the GetStatus method of a PXCache instance. This returns a PXEntryStatus as defined below.
//
// Summary:
// This enumeration specifies the status of a data record. The status of a data
// record changes as a result of manipulations with the data record: inserting,
// updating, or deleting.
public enum PXEntryStatus
{
//
// Summary:
// The data record has not been modified since it was placed in the PXCache object
// or since the last time the Save action was invoked (triggering execution of BLC's
// Actions.PressSave()).
Notchanged = 0,
//
// Summary:
// The data record has been modified, and the Save action has not been invoked.
// After the changes are saved to the database, the data record status changes to
// Notchanged.
Updated = 1,
//
// Summary:
// The data record is new and has been added to the PXCache object, and the Save
// action has not been invoked. After the changes are saved to the database, the
// data record status changes to Notchanged.
Inserted = 2,
//
// Summary:
// The data record is not new and has been marked as Deleted within the PXCache
// object. After the changes are saved, the data record is deleted from the database
// and removed from the PXCache object.
Deleted = 3,
//
// Summary:
// The data record is new and has been added to the PXCache object and then marked
// as Deleted within the PXCache object. After the changes are saved, the data record
// is removed from the PXCache object.
InsertedDeleted = 4,
//
// Summary:
// An Unchanged data record can be marked as Held within the PXCache object to avoid
// being collected during memory cleanup. Updated, Inserted, Deleted, InsertedDeleted,
// or Held data records are never collected during memory cleanup. Any Notchanged
// data record can be removed from the PXCache object during memory cleanup.
Held = 5,
Modified = 6
}
Using the GetStatus method, you can execute conditional logic based on the status of the data record.
For example, let’s say you have a grid with an add button. When the user adds a new record, that record has a status of Inserted until the save button is Pressed or it is deleted. If it is deleted, it’s status changes to InsertedDeleted.
As an example, consider that you want to disable a particular field until a user saves an inserted record.
You could achieve this in the RowSelected event as follows:
protected void MyView_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
MyDAC row = e.Row as MyDAC;
if (row == null)
return;
if (MyView.Cache.GetStatus(row) == PXEntryStatus.Inserted)
{
PXUIFieldAttribute.SetEnabled<MyDAC.myField>(sender, row, false);
}
}