I have a requirement on which the Ship-to Contact & Address in Shipments screen (for Transfer only) will be overridden by using the location of Customer selected from UDF.
The UDF that I have created
A piece of code that I used to test:
#region AddressLine1
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDBScalar(typeof(Search2<SOAddress.addressLine1,
InnerJoin<SOShipment, On<SOAddress.customerID, Equal<SOShipment.customerID>>,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<SOShipment.customerID>>,
InnerJoin<SOShipmentKvExt, On<SOShipment.noteID, Equal<SOShipmentKvExt.recordID>>>>>,
Where<BAccount.acctCD, Equal<Current<SOShipmentKvExt.valueString>>>>))]
public string AddressLine1 { get; set; }
#endregion
Using the above code, the Address Line 1 field remains empty despite the customer in UDF being selected.
I would appreciate an easy-to-understand explanation since I'm fairly new in C#. Thanks!
Edit:
I managed to populate the Ship-to-Contact and Ship-to-Address fields by using the following code:
My DAC Extension:
public class SOShipmentExt : PXCacheExtension<PX.Objects.SO.SOShipment>
{
#region UsrCustomerID
[CustomerActive(DescriptionField = typeof(Customer.acctName))]
[PXUIField(DisplayName = "Customer ID")]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual int? UsrCustomerID { get; set; }
public abstract class usrCustomerID : PX.Data.BQL.BqlInt.Field<usrCustomerID> { }
#endregion
#region UsrShipAddressID
[PXDBInt()]
[PXUIField(DisplayName = "Ship Address ID")]
public virtual Int32? UsrShipAddressID { get; set; }
public abstract class usrShipAddressID : PX.Data.BQL.BqlInt.Field<usrShipAddressID> { }
#endregion
#region UsrShipContactID
[PXDBInt()]
[PXUIField(DisplayName = "Ship Contact ID")]
public virtual Int32? UsrShipContactID { get; set; }
public abstract class usrShipContactID : PX.Data.BQL.BqlInt.Field<usrShipContactID> { }
#endregion
}
My Graph Extension:
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
public virtual void SetShipAddressAndContact(SOShipment shipment, int? shipAddressID, int? shipContactID)
{
SOShipmentExt sOShipmentExt = shipment.GetExtension<SOShipmentExt>();
foreach (SOShipmentAddress address in Base.Shipping_Address.Select())
{
if (address.AddressID < 0)
{
Base.Shipping_Address.Delete(address);
}
}
foreach (SOShipmentContact contact in Base.Shipping_Contact.Select())
{
if (contact.ContactID < 0)
{
Base.Shipping_Contact.Delete(contact);
}
}
}
protected virtual void SOShipment_UsrCustomerID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
SOShipment row = (SOShipment)e.Row;
SOShipmentExt sOShipmentExt = row.GetExtension<SOShipmentExt>();
SOShipmentAddress sOShipment = SelectFrom<SOShipmentAddress>.Where<SOShipmentAddress.customerID.IsEqual<#P.AsInt>>.View.Select(this.Base, sOShipmentExt.UsrCustomerID);
SOShipmentContact sOShipmentContact = SelectFrom<SOShipmentContact>.Where<SOShipmentContact.customerID.IsEqual<#P.AsInt>>.View.Select(this.Base, sOShipmentExt.UsrCustomerID);
if (row != null && sOShipmentExt != null)
{
sOShipmentExt.UsrShipAddressID = sOShipment.AddressID;
sOShipmentExt.UsrShipContactID = sOShipmentContact.ContactID;
}
SetShipAddressAndContact(row, sOShipmentExt.UsrShipAddressID, sOShipmentExt.UsrShipContactID);
#endregion
}
The issues I’m facing now:
Once the document has been saved and I switched to another document, I am unable to access back the previous document that has been saved and it returns below errors:
ShipAddressID - Specified cast is not valid
ShipContactID - Specified cast is not valid
If the selected Customer ID doesn’t have any data in SOShipmentAddress or SOShipmentContact, then it won’t allow me to select the customer. Ideally, I should be able to select the customer and the fields should be auto populated with address details from Address table.
I would appreciate any help since I’m getting really close to solving this.
SOAddress is a table of addresses that are linked to SOs & Shipments. Since this data generally doesn't change very much, the idea is that records will be linked to multiple SOs and shipments. When an address is changed for a Customer, a new record is created in SOAddress. That way, historical data is preserved intact. Thus, records in the table should not be edited. So, rather than thinking about overwriting the address information in SOAddress, you should think about overwriting the ShipAddressID linked to the Shipment to either a new address you create or more likely an already existing one.
Related
I have added custom fields in customization form using the customization form, steps i have added:
1) Go to shipment form and select Transaction Grid.
2) Select Add fields.
3) Select custome and Add 4 fields and save and publish.
4) Add all 4 fields and select used and save.
5) and publish again and all 4 columns are visible.
6) I have added a user fields name Aloow (PXDBBool), UsrPClocation(Location) and UsrPCwarehouse(Site),
and i set the below attribute in warehour and location.
7) But on SOSHipLine_InventotyID_FieldUpdate event, i am setting Allow, location, warehouse all 3 values, but values are not showing in Grid, what is the resoon?
#region UsrQCSiteID
[PXUIField(DisplayName = "PC Warehouse")]
[SiteAvail(typeof(SOShipLine.inventoryID), typeof(SOShipLine.subItemID))]
[PXUIRequired(typeof(Where<usrAllow, Equal<True>>))]
[PXUIEnabled(typeof(Where<usrAllow, Equal<True>>))]
[PXDefault()]
public virtual int? UsrPCSiteID {
get; set;
}
public abstract class usrPCSiteID:PX.Data.BQL.BqlInt.Field<usrPCSiteID> {
}
#endregion UsrPCSiteID
#region UsrPCLocationID
[PXUIField(DisplayName = "PC Location")]
[SOLocationAvail(typeof(SOShipLine.inventoryID), typeof(SOShipLine.subItemID), typeof(SOShipLineExt.usrPCSiteID), typeof(SOLine.tranType), typeof(SOShipLine.invtMult))]
[PXUIRequired(typeof(Where<usrQCRequired, Equal<True>>))]
[PXUIEnabled(typeof(Where<usrQCRequired, Equal<True>>))]
[PXDefault()]
public virtual int? UsrPCLocationID {
get; set;
}
public abstract class usrPCLocationID:PX.Data.BQL.BqlInt.Field<usrPCLocationID> {
}
#endregion UsrPCLocationID
#region Allow
[PXDBBool]
[PXUIField(DisplayName = "Allow")]
public virtual bool? UsrAllow {
get; set;
}
public abstract class usrAllow:PX.Data.BQL.BqlBool.Field<usrAllow> {
}
#endregion
IS SOShipLine allow updating custom values?
The steps that you described look correct.
I recreated this scenario locally:
1 - My DAC extension looks as follows:
public class SOShipLineExt : PXCacheExtension<PX.Objects.SO.SOShipLine>
{
#region UsrPCSiteID
[PXUIField(DisplayName = "PC Warehouse")]
[SiteAvail(typeof(SOShipLine.inventoryID), typeof(SOShipLine.subItemID))]
public virtual int? UsrPCSiteID {
get; set;
}
public abstract class usrPCSiteID:PX.Data.BQL.BqlInt.Field<usrPCSiteID> {
}
#endregion UsrPCSiteID
#region UsrPCLocationID
[PXUIField(DisplayName = "PC Location")]
[SOLocationAvail(typeof(SOShipLine.inventoryID), typeof(SOShipLine.subItemID), typeof(SOShipLineExt.usrPCSiteID), typeof(SOShipLine.tranType), typeof(SOShipLine.invtMult))]
public virtual int? UsrPCLocationID {
get; set;
}
public abstract class usrPCLocationID:PX.Data.BQL.BqlInt.Field<usrPCLocationID> {
}
#endregion UsrPCLocationID
#region Allow
[PXDBBool]
[PXUIField(DisplayName = "Allow")]
public virtual bool? UsrAllow {
get; set;
}
public abstract class usrAllow:PX.Data.BQL.BqlBool.Field<usrAllow> {
}
#endregion
}
Notes about the DAC Extension:
I removed references to PXUIEnabled and PXUIRequired. If you are looking to disable the Site and the Location based on the checkbox's value, I recommend you manage this logic in the RowSelected event. (it may be feasible with your approach but I have not used it before)
The PXDefault references were also removed, given that in most cases the Shipment is created directly from the Sales Order page. As you have it right now, the field is mandatory but no default value is being assigned which will cause an error. You have 2 options: 1) indicate the value in the PXDefault() attribute, or 2) Set the property PXPersistingCheck.Nothing.
Note that your SOLocationAvail attribute has an error in the 4th parameter. You should use typeof(SOShipLine.tranType) instead of typeof(SOLine.tranType). This was generating an error when the shipment was created from the SO.
2 - My FieldUpdated event looks as follows:
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
protected virtual void SOShipLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
if (e.Row == null) return;
SOShipLine line = (SOShipLine)e.Row;
SOShipLineExt lineExt = cache.GetExtension<SOShipLineExt>(line);
if (lineExt != null)
{
lineExt.UsrAllow = true;
lineExt.UsrPCSiteID=154;
lineExt.UsrPCLocationID=155;
}
}
}
Notes about the Graph extension:
I hard-coded the Warehouse and Location values. I recommend you do the same on your end while testing is being done, just make sure that the IDs exist in your DB, or that you query the CD value and then use its corresponding ID value.
Results:
When the Shipment is created from a SO, the values are being correctly assigned:
I want to show which user created Invoice, for this i have added default Acumatica field, but the label is showing as Created By, how can i change that label name to "Invoice Created By". Please have a look at below screenshot for field am referring to.
You could use PXUIFieldAttribute.SetDisplayName static method to change DAC field’s display name. This change will be applicable only for Sales Invoice Entry Graph (SO303000 screen)
public class SOInvoiceEntryPXDemoExt : PXGraphExtension<SOInvoiceEntry>
{
public override void Initialize()
{
PXUIFieldAttribute.SetDisplayName<ARInvoice.createdByID>(Base.Document.Cache, "Invoice Created By");
}
}
If you need display name changed for this field in all screens, you need to have DAC Extension as below:
With this, attributes specified in an extension DAC apply to DAC class in every Graph of the application unless a Graph replaces them with other attributes.
public class ARInvoicePXDemoExt : PXCacheExtension<ARInvoice>
{
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXUIField(DisplayName = "Invoice Created By", Enabled = false, IsReadOnly = true)]
public virtual Guid? CreatedByID { get; set; }
}
You need to add CreatedByID field on screen SO303000
And set DisplayMode property to Text.
The 'CreatedByID' I believe is an audit field and therefore cannot easily change the ui of the additional data fields available through the control. The resolution I would suggest is a non database backed UI field that is populated during row selecting. Example can be found below :
public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
public virtual void SOOrder_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
SOOrder row = e.Row as SOOrder;
if(row != null)
{
SOOrderExtension rowExt = PXCache<SOOrder>.GetExtension<SOOrderExtension>(row);
Users user = PXSelectReadonly<Users, Where<Users.pKID, Equal<Required<Users.pKID>>>>.Select(this.Base, row.CreatedByID);
if(user != null)
{
rowExt.InvoiceCreatedBy = user.DisplayName;
}
}
}
}
public class SOOrderExtension : PXCacheExtension<SOOrder>
{
public abstract class invoiceCreatedBy : PX.Data.IBqlField
{
}
[PXString]
[PXUIField(DisplayName = "Invoice Created By")]
public virtual string InvoiceCreatedBy { get; set; }
}
I want to achieve, is to get the QtyOnHand of a specific inventoryID in InSiteStatus table.
I created a DAC for InventoryID and labeled it as "Style" and another for QtyOnHand.
I used FieldUpdated event handler, so every time an user selects a new inventoryID it will update the QtyOnHand field.
Here's my work.
DAC:
public class AllocationFilter: IBqlTable
{
#region Style
public abstract class style : IBqlField
{
}
[PXInt]
[PXUIField(DisplayName = "Style")]
[PXSelector(typeof(InventoryItem.inventoryID)
, typeof(InventoryItem.inventoryCD)
, typeof(InventoryItem.descr)
, SubstituteKey = typeof(InventoryItem.inventoryCD)
)]
public virtual int? Style { get; set; }
#endregion
#region OnHand
public abstract class onHand : IBqlField
{ }
[PXDecimal()]
[PXUIField(DisplayName = "On Hand", Enabled = false)]
public virtual decimal? OnHand { get; set; }
#endregion
}
Event Handler:
protected void AllocationFilter_Style_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
// Obtain the new data record that contains the updated
// values of all data fields
AllocationFilter filterAlloc = (AllocationFilter)e.Row;
if (filterAlloc == null)
return;
// This is where the error triggers...
PXResultset<INSiteStatus> insitestatus = PXSelect<INSiteStatus,
Where<INSiteStatus.inventoryID,
Equal<AllocationFilter.style>>>.Select(this);
foreach (INSiteStatus sitestatus in insitestatus)
{
filterAlloc.OnHand = sitestatus.QtyOnHand;
}
}
I think there is a problem with my PXResultSet, can you help me guys?
You have two options that I see here.
One, create a View for this
public PXSelect<INSiteStatus,Where<INSiteStatus.inventoryID,Equal<Current<AllocationFilter.style>>> StyleStatus;
Then in your event handler
foreach (INSiteStatus sitestatus in StyleStatus.Select())
{......}
Or two, inline like you have it
PXResultset<INSiteStatus> insitestatus = PXSelect<INSiteStatus,
Where<INSiteStatus.inventoryID,
Equal<Required<INSiteStatus.inventoryID>>>.Select(this,filterAlloc.Style);
Unless you need greater control of the select statement, I would use the View
I have an extension graph onto INReceiptEntry. I set up a view for the custom DAC that I want a cache generated for that will get objects inserted into. After I generate one of the objects I want to insert into the cache, I use ViewName.Insert(Object); (also used ViewName.Cache.Insert(Object) with same results) within the graph extension's RowPersisting handler. This normally would store the data items in the corresponding database data table associated to the DAC, but nothing is stored in the DB. Instead of If statement fires and I get a popup stating that the object wasn't inserted. Here is my code:
public class INReceiptEntry_Extension : PXGraphExtension<INReceiptEntry>
{
public PXSelect<EMPWorkOrderINRegister> WorkOrderINRegisters;
#region Event Handlers
protected void INRegister_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (INRegister)e.Row;
var rowExt = PXCache<INRegister>.GetExtension<INRegisterExt>(row);
//Get Target Objects
foreach (INTranSplit split in PXSelect<INTranSplit, Where<INTranSplit.refNbr,
Equal<Required<INRegister.refNbr>>, And<INTranSplit.tranType, Equal<TranType>>>>
.Select(Base, Base.CurrentDocument.Current.RefNbr))
{
EMPWorkOrderINRegister WOINR = new EMPWorkOrderINRegister();
WOINR.Woid = rowExt.Usrwoid;
WOINR.RefNbr = split.RefNbr;
WOINR.SplitLineNbr = split.SplitLineNbr;
if (WorkOrderINRegisters.Insert(WOINR) == null)
{
Base.CurrentDocument.Ask("Did not insert WOINR:" + WOINR.RefNbr.ToString() + ", " + WOINR.SplitLineNbr.ToString(), MessageButtons.OK);
return;
}
}
}
#endregion
}
Any reason this isn't inserting into the custom cache? Does using a graph extension or executing this cache insert in a Persisting function have anything to do with why this is failing?
By request, the DAC:
using System;
using PX.Data;
using PX.Objects.IN;
namespace Manufacturing
{
[Serializable]
public class EMPWorkOrderINRegister : IBqlTable
{
#region Id
[PXDBIdentity()]
[PXUIField(DisplayName = "Id")]
public int? Id { get; set; }
public class id : IBqlField { }
#endregion
#region Woid
[PXDBInt()]
[PXUIField(DisplayName = "Woid")]
public int? Woid { get; set; }
public class woid : IBqlField { }
#endregion
#region RefNbr
[PXDBString(15, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Receipt Number")]
public string RefNbr { get; set; }
public class refNbr : IBqlField { }
#endregion
#region SplitLineNbr
[PXDBInt()]
[PXUIField(DisplayName = "Split Line Nbr")]
public int? SplitLineNbr { get; set; }
public class splitLineNbr : IBqlField { }
#endregion
#region AvailableSNs
[PXString()]
[PXUIField(DisplayName = "Available SNs")]
public string AvailableSNs { get; set; }
public class availableSNs : IBqlField { }
#endregion
[PXString()]
[PXDBScalar(typeof(Search<INTranSplit.lotSerialNbr, Where<INTranSplit.refNbr, Equal<EMPWorkOrderINRegister.refNbr>,
And<INTranSplit.splitLineNbr, Equal<EMPWorkOrderINRegister.splitLineNbr>>>>))]
public string SelectedSN { get; set; }
public class selectedSN : IBqlField { }
}
}
Eric, there is one major issue with your DAC, which is the lack of key fields.
Additional area of improvement in the INRegister_RowPersisting handler. RowPersisting handlers are designed to either validate the data record before it's committed to database or cancel the commit operation of a specific data record. For more details, please refer to the Acumatica Framework API Reference
The better approach for your scenario is to override the Persist method and insert missing EMPWorkOrderINRegister records before execution of the base Persist method. It's also a good idea to use a try-catch statement and delete EMPWorkOrderINRegister records with the Inserted status if base Persist method had failed.
I have a custom processing page. The main DAC of the data view is ARRegister, but there is the data view delegate. Both the view & delegate join ARCashSale & ARInvoice to the main DAC, The reason for this is...some records are cash sales, and others are invoices, overdue charges, ect. A few grid columns are included, which displays data specific to a cash sale. I invoke a static method in my process graph to assign the process delegate. The method runs with no errors.
In the data view delegate, I check the doc type for each record returned from the BQL.
If cash sale, then
yield return new PXResult<ARRegister, ARCashSale>(register, cashsale)
ELSE
yield return new PXResult<ARRegister>(register)
The reason for the delegate is to check some other conditions which cannot be determined using standard BQL. I notice the data in the column specific to a cash sale disappears after the user selects 'Process All'. I am unable to determine the reason. Checking to see if others have experienced this.
DataView
public PXProcessingJoin<ARRegister,
LeftJoin<cs.ARCashSale, On<ARRegister.docType, Equal<cs.ARCashSale.docType>, And<ARRegister.refNbr, Equal<cs.ARCashSale.refNbr>>>,
LeftJoin<ARInvoice, On<ARRegister.docType, Equal<ARInvoice.docType>, And<ARRegister.refNbr, Equal<ARInvoice.refNbr>>>,
InnerJoin<Customer,On<ARRegister.customerID,Equal<Customer.bAccountID>>>>>,
Where2<Where<ARRegister.released, Equal<True>, And<ARRegister.branchID, Equal<Current<AccessInfo.branchID>>>>,
And<Where<Customer.finChargeApply,Equal<True>>>>> Registers;
This is an older question, but I had a similar issue.
You need to add a boolean field named "Selected" to DACs you want to process.
The way I solved it was using a local DAC.
You can make it inherit from ARRegister and just add the required field.
In my case I used PXProjection, inherited from the main DAC and added the fields I needed from the joined DACs. Note that you need to add the BqlField = typeof(DAC.field) property to the type attribute of these fields to map them to the correct DAC.
Then in the PXProcessing view you just use your local DAC.
Also, it is very useful to try the Request Profiler screen (SM205070) when troubleshooting BQL.
Basically in processing screens sub DAC (other than Main DAC in view), filed values will not persist once the process completed.
In this case, the PXProjection will help us to persist the values even after completion of the process for the rows/records in processing screens.
Please find the sample Projection View and DAC below.
[PXProjection(typeof(Select2<SOShipment, InnerJoin<SOOrderShipment,
On<SOOrderShipment.shipmentNbr, Equal<SOShipment.shipmentNbr>,
And<SOShipment.status, Equal<SOShipmentStatus.confirmed>>>,
InnerJoin<SOOrder, On<SOOrderShipment.orderType, Equal<SOOrder.orderType>,
And<SOOrderShipment.orderNbr, Equal<SOOrder.orderNbr>>>>>>))]
Projection DAC:
[Serializable]
public class ProjectionShipmentDAC : IBqlTable
{
#region Selected
public abstract class selected : IBqlField
{
}
protected bool? _Selected = false;
[PXBool]
[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected
{
get
{
return _Selected;
}
set
{
_Selected = value;
}
}
#endregion
#region Status
[PXDBString(1, IsFixed = true, BqlField = typeof(SOShipment.status))]
[PXUIField(DisplayName = "Status")]
[SOShipmentStatus.List()]
public virtual string Status { get; set; }
public abstract class status : IBqlField { }
#endregion
#region ShipmentNbr
[PXDBString(15, IsKey = true, IsUnicode = true, BqlField = typeof(SOShipment.shipmentNbr))]
[PXUIField(DisplayName = "Shipment Nbr.")]
public virtual string ShipmentNbr { get; set; }
public abstract class shipmentNbr : IBqlField { }
#endregion
#region ShipDate
[PXDBDate(BqlField = typeof(SOShipment.shipDate))]
[PXUIField(DisplayName = "Shipment Date")]
public virtual DateTime? ShipDate { get; set; }
public abstract class shipDate : IBqlField { }
#endregion
#region CustomerID
[PXDBInt(BqlField = typeof(SOShipment.customerID))]
[PXUIField(DisplayName = "Customer")]
[PXSelector(typeof(Customer.bAccountID), new Type[] { typeof(Customer.acctCD), typeof(Customer.acctName) },
SubstituteKey = typeof(Customer.acctCD), DescriptionField = typeof(BAccount.acctName))]
public virtual int? CustomerID { get; set; }
public abstract class customerID : IBqlField { }
#endregion
#region Shipped Quantity
[PXDBDecimal(BqlField = typeof(SOShipment.shipmentQty))]
[PXUIField(DisplayName = "Shipped Quantity")]
public virtual decimal? ShipmentQty { get; set; }
public abstract class shipmentQty : IBqlField { }
#endregion
}
Have you played around with MatrixMode and/or SyncPosition on your page grid? You might need SyncPosition="True"
Also, does the issue occur if not using process all? (process 1 or 2 rows)