I am having trouble to find a solution in how to save a char type field depending on the Tab that the user is positioned. I have "Fringe", "Overhead" and "G&A" tabs where the 3 of them share the same database table. The problem is that I want to save this Type field ("F","O" or "G") depending on the Tab that I am in.
Tabs and Type field in the grid
The solution that I am trying, was to create 3 different DAC Unbounded for each tab and save the information on the datamembers bounded to these tabs (the type field is included on each tab). After doing this, I used the Event Handler RowPersisting to insert manually on database (which it worked correctly) and also I needed to implement the RowDeleting to delete a row if needed. This is where this solution is not working.
Basically the RowDeleting EventHandler is not showing the correct information of the current row in which this event was triggered.
IU Row vs What the event is showing as the current row
I would look into using projections (PXProjection) in Acumatica so you can create additional DACs representing your different types (as they are located on different Tabs but stored in the same table). This way you don not have to use any events to do any complex/tricky logic against the framework as you have described you are doing.
I put together a simple example below. Note the 3 projection DACs that point to the same main dac. This allows the records to be all stored inMyTable in the database but each will have their own cache.
Here I define my different types...
public class MyDacType
{
public const string TypeA = "A";
public const string TypeB = "B";
public const string TypeC = "B";
public class typeA : Constant<string>
{
public typeA() : base(TypeA) { }
}
public class typeB : Constant<string>
{
public typeB() : base(TypeB) { }
}
public class typeC : Constant<string>
{
public typeC() : base(TypeC) { }
}
/// <summary>
/// List attribute for display of user friendly value
/// </summary>
public class ListAttribute : PXStringListAttribute
{
public ListAttribute()
: base(new string[]
{
TypeA,
TypeB,
TypeC
}, new string[]
{
"Type A",
"Type B",
"Type C"
})
{
}
}
}
This is my main table...
/// <summary>
/// Main database DAC
/// </summary>
[Serializable]
public class MyTable : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true)]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1)]
[PXDefault]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type")]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true)]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
I created 3 projections (one for each tab)...
/// <summary>
/// DAC representing Type A (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeA>>>), Persistent = true)]
public class MyTableTypeA : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeA)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
/// <summary>
/// DAC representing Type B (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeB>>>), Persistent = true)]
public class MyTableTypeB : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeB)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
/// <summary>
/// DAC representing Type C (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeC>>>), Persistent = true)]
public class MyTableTypeC : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeC)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
Now in my graph I create 3 views (1 for each PXProjection dac). I also do not need to display the DacType field since it will automatically default to the correct value.
public class MyGraph : PXGraph<MyGraph>
{
// Some other views...
/// <summary>
/// View for tab 1
/// </summary>
public PXSelect<MyTableTypeA> TypeA;
/// <summary>
/// View for tab 2
/// </summary>
public PXSelect<MyTableTypeB> TypeB;
/// <summary>
/// View for tab 3
/// </summary>
public PXSelect<MyTableTypeC> TypeC;
// When using events and cache attached you use the DAC name. Ex:
// protected virtual void MyTableTypeB_RowDeleting(PXCache cache, RowDeletingEvents e) { }
}
Related
I have a Rich Text field attached to the PMQuote and CRQuote DACs. On the CRQuote, the user field is on the standalone class and the regular class, and that is working as desired. However, Acumatica's reporting does not show the HTML formatting so I am creating an unbound Plain Text field to put on the reports and in GI's. This field works fine on the PMQuote, but not on the CRQuote. On the CRQuote, the field is there, but it is always blank. I'm sure it is something to do with the projection, but I'm not sure how it should be created.
Here is the PMQuote field (working properly)
[PXString(IsUnicode = true)]
[PXUIField(Visible = false, DisplayName = "Scope Text")]
public virtual String UsrScopePlainText
{
get
{
return PX.Data.Search.SearchService.Html2PlainText(UsrScope);
}
}
public abstract class usrScopePlainText : PX.Data.BQL.BqlString.Field<usrScopePlainText> { }
And here is what I have on the CRQuote (not working):
public class CRQuoteExt : PXCacheExtension<CRQuote>
{
#region UsrScope
[PXDBText(IsUnicode = true, BqlField = typeof(CRQuoteStandaloneExt.usrScope))]
[PXUIField(DisplayName = "Scope")]
public virtual string UsrScope { get; set; }
public abstract class usrScope : IBqlField { }
#endregion
#region UsrScopePlainText
[PXString(IsUnicode = true)]
[PXUIField(Visible = false, DisplayName = "Scope Text")]
public virtual String UsrScopePlainText
{
get
{
return PX.Data.Search.SearchService.Html2PlainText(UsrScope);
}
}
public abstract class usrScopePlainText : IBqlField { }
#endregion
}
public class CRQuoteStandaloneExt : PXCacheExtension<PX.Objects.CR.Standalone.CRQuote>
{
#region UsrScope
[PXDBText(IsUnicode = true)]
[PXUIField(DisplayName = "Scope")]
public virtual string UsrScope { get; set; }
public abstract class usrScope : IBqlField { }
#endregion
#region UsrScopePlainText
[PXString(IsUnicode = true)]
[PXUIField(Visible = false, DisplayName = "Scope Text")]
public virtual String UsrScopePlainText
{
get
{
return PX.Data.Search.SearchService.Html2PlainText(UsrScope);
}
}
public abstract class usrScopePlainText : IBqlField { }
#endregion
}
Thanks!
An alternative solution could be to have a reusable attribute that you can attach to any field. I think this is cleaner than adding logic directly in the Data Access class...
using PX.Objects.IN;
using PX.Data;
using System;
namespace PX.Objects.IN
{
public class InventoryItemPlainTextBodyExt : InventoryItem
{
[HtmlToText(typeof(InventoryItem.body))]
[PXDependsOnFields(typeof(InventoryItem.body))]
[PXUIField(DisplayName="Body (Plain Text)")]
public virtual string BodyPlainText { get; set; }
public abstract class bodyPlainText : PX.Data.BQL.BqlString.Field<bodyPlainText> { }
}
[PXString]
public class HtmlToTextAttribute : PXEventSubscriberAttribute, IPXFieldSelectingSubscriber
{
protected Type _htmlField;
public HtmlToTextAttribute(Type htmlField) :base()
{
_htmlField = htmlField;
}
public void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
e.ReturnValue = PX.Data.Search.SearchService.Html2PlainText(sender.GetValue(e.Row, _htmlField.Name) as string);
}
}
}
I'm not sure what happened, but I put the original code I posted above back into the customization project and it started working as expected.
We have 2 DAC - Master and Child
Master DAC
#region MasterID
public abstract class masterID:PX.Data.BQL.BqlInt.Field<masterID> { }
protected int? _MasterID;
[PXDBIdentity()]
[PXUIField(Visibility = PXUIVisibility.Invisible)]
[PXReferentialIntegrityCheck]
public virtual int? MasterID
{
get {return this._MasterID;}
set {this._MasterID = value;}
}
#endregion
#region MasterCD
public abstract class masterRoutingCD:PX.Data.BQL.BqlString.Field<masterCD> { }
protected string _MasterRoutingCD;
[BomID(DisplayName = "Master #", IsKey = true, Required = true,
Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault]
[Rev.Key(typeof(Setup.pMMasterNumberSequenceID),
typeof(Master.masterCD),
typeof(Master.revisionNo),
typeof(Master.masterCD),
typeof(Master.revisionNo)
)]
public virtual string MasterCD
{
get {return this._MasterCD;}
set {this._MasterCD = value;}
}
#endregion
#region RevisionNo
public abstract class revisionNo:PX.Data.IBqlField { }
protected string _RevisionNo;
[RevisionIDField(IsKey = true, Visibility = PXUIVisibility.SelectorVisible,
Required = true)]
[PXDefault(typeof(Master.defaultRevisionNo),
PersistingCheck = PXPersistingCheck.Nothing)]
[Rev.ID(typeof(Master.defaultRevisionNo),
typeof(Master.masterCD),
typeof(Master.revisionNo),
typeof(Master.revisionNo),
typeof(Master.description),
typeof(Master.fromDate),
typeof(Master.toDate))]
public virtual string RevisionNo
{
get {return this._RevisionNo;}
set {this._RevisionNo = value;}
}
#endregion
Child DAC
public abstract class childID:PX.Data.BQL.BqlInt.Field<childID> { }
protected int? _ChildID;
[PXDBIdentity()]
//[PXReferentialIntegrityCheck]
public virtual int? ChildID
{
get {return this._ChildID;}
set {this._ChildID = value;}
}
#endregion
#region MasterID
public abstract class masterID:PX.Data.BQL.BqlInt.Field<masterID> { }
protected int? _MasterID;
[PXDBInt()]
[PXDBDefault(typeof(Master.masterID))]
[PXParent(typeof(Select<Master, Where<Master.masterRoutingCD, Equal<Current<masterCD>>,
And<Master.revisionNo, Equal<Current<revisionNo>>>>>))]
public virtual int? MasterID
{
get {return _MasterID;}
set {_MasterID = value;}
}
#endregion MasterID
#region MasterCD
public abstract class masterCD:PX.Data.BQL.BqlString.Field<masterCD> { }
protected string _MasterCD;
[PXDBDefault(typeof(Master.masterCD))]
[PXDBString(IsKey = true, IsUnicode = true)]
public virtual string MasterCD
{
get {return this._MasterCD;}
set {this._MasterCD = value;}
}
#endregion
#region Revision
public abstract class revisionNo:PX.Data.BQL.BqlString.Field<revisionNo> {}
[PXDBString(15, IsKey = true, IsUnicode = true)]
[PXDBDefault(typeof(Master.revisionNo))]
public virtual string RevisionNo { get; set; }
#endregion Revision
public abstract class stepsID:PX.Data.BQL.BqlInt.Field<stepsID> { }
[OperationCDField(IsKey =true, DisplayName = "Steps ID",
Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
//[PXUIField(DisplayName = "Process Steps ID")]
public virtual string StepsID { get; set; }
Graph - MasterMaint
public class MasterMaint:PXRevisionableGraph<MasterMaint, Master,
Master.masterCD, Master.revisionNo>
{
public PXSelect<Child, Where<Child.masterCD, Equal<Current<Master.masterCD>>,
And<Child.revisionNo, Equal<Current<Master.revisionNo>>>>> ChildRecords;
#region Override
public override bool CanClipboardCopyPaste()
{
return false;
}
public override bool CanCreateNewRevision(MasterMaint fromGraph, MasterMaint toGraph,
string keyValue, string revisionValue, out string error)
{
// Always returns true as new revisions can be created at any time
error = string.Empty;
return true;
}
public override void CopyRevision(MasterMaint fromGraph, MasterMaint toGraph,
string keyValue, string revisionValue)
{
if(toGraph?.Documents?.Current == null || fromGraph?.Documents?.Current == null)
{
// api calls should create new revs on their own - this causes issues
// when calling from api so we need to turn the copy rev logic off
return;
}
toGraph.Documents.Cache.SetDefaultExt<EWPMMasterRouting.status>
(toGraph.Documents.Current);
if(SkipAutoCreateNewRevision())
{
return;
}
CopyChildRecords(fromGraph.Documents.Current.MasterRoutingCD,
fromGraph.Documents.Current.RevisionNo, toGraph.Documents.Current.MasterID,
keyValue, revisionValue, false);
}
internal virtual void CopyChildRecords(string sourceID, string sourceRevisionNo,
int? newMasterID, string newMasterCD, string newRevisionID, bool copyNotes)
{
foreach(Child fromRow in PXSelect<Child,
Where<Child.masterCD, Equal<Required<Child.masterCD>>,
And<Child.revisionNo, Equal<Required<Child.revisionNo>>>>>
.Select(this, sourceID, sourceRevisionNo))
{
var toRow = PXCache<Child>.CreateCopy(fromRow);
toRow.MasterID = newMasterRoutingID;
toRow.ChildID = null;
toRow.MasterCD = newMasterCD;
toRow.RevisionNo= newRevisionID;
toRow = ChildRecords.Insert(toRow);
}
}
#endregion
}
Issue - When the value is changed in the Revision the record is displayed with new revision number keeping the CD fields as for previous revision and all the child.
That is all correct, But when the record is saved, there is error "Another process has updated the Record, your changes will be lost"
Why there is a Error
In Acuamtica we have NoteID column unique across the system If you try to create a record with duplicating NoteID field value you'll get "Another process has updated the record" exception because it consider that you are updating the same record.
In you case when you copy revision you do not reset the NoteID value for the record so you actually try to insert another record with the same value.
You'll need to add the following line to CopyRevision method
toGraph.Documents.Cache.SetDefaultExt<EWPMMasterRouting.noteID>(toGraph.Documents.Current);
I have a button in which, when pressed, I want to show or hide rows in a grid based on certain criteria. Is it possible to change the PXSelect a view uses on the fly so that it re-queries the database and retrieves different results? I will, of course, be querying the same table and not changing up the structure of the View or grid.
The code below adds a non-visible field to the header record that is set by the button press this value is then used by the child records view delegate to determine based on the child records criteria (in this case a Boolean on each child) if they are shown.
public sealed class APInvoiceExtension : PXCacheExtension<APInvoice>
{
#region UsrShowAll
public abstract class usrShowAll : IBqlField
{
}
[PXBool]
public bool? UsrShowAll { get; set; }
#endregion
}
public sealed class APTranExtension : PXCacheExtension<APTran>
{
#region UsrHidden
public abstract class usrHidden : IBqlField
{
}
[PXDBBool]
[PXUIField(DisplayName = "Hidden", Enabled = false)]
public bool? UsrHidden { get; set; }
#endregion
}
public class APInvoiceEntryExtension : PXGraphExtension<APInvoiceEntry>
{
public PXAction<APInvoice> SHW;
[PXUIField(DisplayName = "Show All Records", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXButton]
protected void sHW()
{
if (Base.Document.Current != null)
{
APInvoiceExtension docExt = Base.Document.Current.GetExtension<APInvoiceExtension>();
docExt.UsrShowAll = !(docExt.UsrShowAll ?? false);
}
}
protected virtual IEnumerable transactions()
{
bool showAll = Base.Document.Current != null ? (Base.Document.Current.GetExtension<APInvoiceExtension>().UsrShowAll ?? false) : false;
APTran tran;
foreach (PXResult<APTran, POReceiptLine> res in Base.Transactions.Select())
{
tran = res[0] as APTran;
if (!showAll)
{
if (!(tran.GetExtension<APTranExtension>().UsrHidden ?? false))
{
yield return res;
}
}
else
{
yield return res;
}
}
}
}
I am trying to create a processing page to extract data from several tables which will be used to update the EDI service item list. I keep getting an error that states the specified cast for BasePrice is not valid.
This is simply an internal DAC in the BLC. There is no physical table in the database. If I exclude my BasePrice field everything works fine. If I include it, the insert gets the error. See the code below.
public class EDInventoryProcess : PXGraph<EDInventoryProcess>
{
public PXCancel<EDInventoryFilter> Cancel;
public PXFilter<EDInventoryFilter> Filter;
[PXFilterable]
public PXFilteredProcessingOrderBy<EDInventory, EDInventoryFilter,
OrderBy<Asc<EDInventory.partnerID, Asc<EDInventory.inventoryCD>>>> EDItem;
protected virtual IEnumerable eDItem()
{
EDItem.Cache.Clear();
var cmd = new PXSelectJoin<InventoryItem,
InnerJoin<INItemXRef, On<InventoryItem.inventoryID, Equal<INItemXRef.inventoryID>>,
InnerJoin<EDPartnerInfo, On<INItemXRef.bAccountID, Equal<EDPartnerInfo.customerID>>>>,
Where<INItemXRef.alternateType, Equal<INAlternateType.cPN>,
And<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>>>>(this);
cmd.View.Clear();
var ret = cmd.Select();
if (ret != null)
{
EDInventoryFilter filt = (EDInventoryFilter)Filter.Cache.Current;
EDInventory edInv = new EDInventory();
foreach (PXResult<InventoryItem, INItemXRef, EDPartnerInfo> record in ret)
{
edInv = new EDInventory();
InventoryItem item = (InventoryItem)record;
INItemXRef xref = (INItemXRef)record;
EDPartnerInfo partner = (EDPartnerInfo)record;
edInv.PartnerID = partner.PartnerID;
edInv.InventoryID = item.InventoryID;
edInv.InventoryCD = item.InventoryCD;
edInv.ItemDescr = item.Descr;
edInv.ItemStatus = item.ItemStatus;
edInv.BaseUnit = item.BaseUnit;
edInv.SalesUnit = item.SalesUnit;
edInv.PurchaseUnit = item.PurchaseUnit;
edInv.BasePrice = Convert.ToDecimal(item.BasePrice);
//This is the lint that generates the error.
edInv = EDItem.Insert(edInv);
EDItem.Cache.SetStatus(edInv, PXEntryStatus.Held);
yield return edInv;
}
}
EDItem.Cache.IsDirty = false;
}
Here is the DAC definition:
[Serializable]
public partial class EDInventoryFilter : IBqlTable
{
#region TradingPartner
public abstract class tradingPartner : PX.Data.IBqlField
{
}
protected string _TradingPartner;
[PXString(15)]
[PXUIField(DisplayName = "Trading Partner")]
[PXStringList(new string[] { }, new string[] { })]
public virtual String TradingPartner { get; set; }
#endregion
#region Action
public abstract class action : PX.Data.IBqlField { }
protected string _Action;
[PXString(15)]
[PXUIField(DisplayName = "Action")]
[PXStringList(new string[] { "P" }, new string[] { "Push to EDI" })]
public virtual String Action { get; set; }
#endregion
}
[Serializable]
public partial class EDInventory : IBqlTable
{
#region PartnerID
public abstract class partnerID : IBqlField { }
[PXString(30, IsUnicode = true, IsKey = true)]
[PXDefault("")]
[PXUIField(DisplayName = "Partner")]
public virtual string PartnerID { get; set; }
#endregion
#region InventoryID
public abstract class inventoryID : PX.Data.IBqlField { }
protected Int32? _InventoryID;
[PXInt]
[PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
public virtual Int32? InventoryID { get; set; }
#endregion
#region InventoryCD
public abstract class inventoryCD : PX.Data.IBqlField { }
protected String _InventoryCD;
[PXDefault()]
[InventoryRaw(IsKey = true, DisplayName = "Inventory ID")]
public virtual String InventoryCD { get; set; }
#endregion
#region ItemDescr
public abstract class itemDescr : PX.Data.IBqlField { }
protected String _ItemDescr;
[PXString(255, IsUnicode = true)]
[PXUIField(DisplayName = "Item Description")]
public virtual String ItemDescr { get; set; }
#endregion
#region ItemStatus
public abstract class itemStatus : PX.Data.IBqlField { }
protected String _ItemStatus;
[PXString(2, IsFixed = true)]
[PXDefault("AC")]
[PXUIField(DisplayName = "Item Status", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String ItemStatus { get; set; }
#endregion
#region BaseUnit
public abstract class baseUnit : PX.Data.IBqlField { }
protected String _BaseUnit;
[PXString]
[PXDefault("")]
[PXUIField(DisplayName = "Base Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String BaseUnit { get; set; }
#endregion
#region SalesUnit
public abstract class salesUnit : PX.Data.IBqlField { }
protected String _SalesUnit;
[PXString]
[PXDefault("")]
[PXUIField(DisplayName = "Sales Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String SalesUnit { get; set; }
#endregion
#region PurchaseUnit
public abstract class purchaseUnit : PX.Data.IBqlField { }
protected String _PurchaseUnit;
[PXString]
[PXDefault("")]
[PXUIField(DisplayName = "Purchase Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String PurchaseUnit { get; set; }
#endregion
#region BasePrice
public abstract class basePrice : PX.Data.IBqlField { }
protected Decimal? _BasePrice;
[PXPriceCost()]
[PXDefault(0.0)]
[PXUIField(DisplayName = "Default Price", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? BasePrice { get; set; }
#endregion
}
I just discovered what might be the answer. I was listing the default value as
[PXDefault(0.0)]
but I found another reference for decimal default as
[PXDefault(TypeCode.Decimal, "0.0")]
which seems to work. I no longer get the error and my processing screen displays as expected. I had assumed the default value drew its type from the object.
Yes for Decimal fields set [PXDefault(TypeCode.Decimal, "0.0")] attribute to avoid casting issues.
This is inside an extension of a BLC (extending PXGraphExtension):
[PXOverride]
protected virtual IEnumerable resultRecords()
{
foreach (PXResult<InventoryTranHistEnqResult, INTran> item in list)
{
PXResult<POReceipt> receiptResult = PXSelect<POReceipt, Where<POReceipt.receiptNbr, Equal<Required<POReceipt.receiptNbr>>>>.Select(Base, "999");
POReceipt receipt = (POReceipt)receiptResult;
PXTrace.WriteInformation(receipt.ReceiptNbr); // CORRECT
PXTrace.WriteInformation(receipt.VendorID); // INCORRECT
}
}
The Vendor ID of the receipt seems to be wrong, but the other details from the record seem to be correct? Here is the DAC for POReceipt. Do I need to do something to make the right Vendor ID get selected?
public partial class POReceipt : PX.Data.IBqlTable, PX.Data.EP.IAssign {
#region Selected
#region ReceiptType
#region ReceiptNbr
#region SiteID
public abstract class siteID : IBqlField { }
[IN.Site(DisplayName = "Warehouse")]
public int? SiteID
{
get;
set;
}
#endregion
#region VendorID
public abstract class vendorID : PX.Data.IBqlField
{
}
protected Int32? _VendorID;
[Vendor(typeof(Search<BAccountR.bAccountID,
Where<BAccountR.type,
Equal<BAccountType.companyType>,
Or<Vendor.type,
NotEqual<BAccountType.employeeType>>>>), Visibility = PXUIVisibility.SelectorVisible, CacheGlobal = true, Filterable = true)]
[PXRestrictor(typeof(Where<Vendor.status, IsNull,
Or<Vendor.status,
Equal<BAccount.status.active>,
Or<Vendor.status,
Equal<BAccount.status.oneTime>>>>), AP.Messages.VendorIsInStatus, typeof(Vendor.status))]
[PXDefault()]
[PXFormula(typeof(Switch<Case<Where<POReceipt.receiptType, Equal<POReceiptType.transferreceipt>>, Selector<POReceipt.siteID, Selector<INSite.branchID, Branch.branchCD>>>, POReceipt.vendorID>))]
public virtual Int32? VendorID
{
get
{
return this._VendorID;
}
set
{
this._VendorID = value;
}
}
#endregion