I am working on making a thumbnail image on the Sales Order lines for the Document Details when the InventoryID is selected. The image however does not populate to the grid whenever I select the InventoryID in the line. Here is what I have so far:
DAC Extension:
namespace PX.Objects.IN
{
public class InventoryItemExt : PXCacheExtension<InventoryItem>
{
#region ThumbnailURL
public abstract class thumbnailURL : IBqlField
{ }
[PXString]
public string ThumbnailURL { get; set; }
#endregion
}
}
Code Extension:
using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;
namespace Combined
{
public class SOLineExt : PXCacheExtension<SOLine>
{
#region ThumbnailURL
public abstract class thumbnailURL : IBqlField
{ }
[PXString]
public string ThumbnailURL { get; set; }
#endregion
}
public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
{
public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
{
baseMethod.Invoke(sender, e);
if(e.Row!=null)
{
var row = e.Row as SOLine;
if (row.InventoryID != null)
{
InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
{
if(currentLineItem.StkItem==true)
{
InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
foreach (Guid fileID in files)
{
PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
{
row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
break;
}
}
}
else
{
NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
foreach (Guid fileID in files)
{
PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
{
row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
break;
}
}
}
}
}
}
}
}
}
ASPX Code:
Code in the Grid:
<px:PXGridColumn DataField="ThumbnailURL" Width="300px" Type="Icon" />
Code on the InventoryID SegmentMask:
<px:PXSegmentMask CommitChanges="True" ID="edInventoryID" runat="server" DataField="InventoryID" AllowEdit="True" >
<GridProperties>
<Columns>
<px:PXGridColumn Type="Icon" DataField="ThumbnailURL" Width="300px" AutoGenerateOption="Add" />
</Columns>
</GridProperties>
</px:PXSegmentMask>
I did find a post about adding an image to the InventoryID Selector and it has a different method of adding images to that grid, does the same apply here? Here is the other post: How to show images inside selector lookup?
I have changed my code above to match the other post but now I am receiving this error:
\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context
\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context
Adding code from the first answer below but now the grid column is showing up blank:
Update 1: FIXED
I have redone all the code above to answer 1 along with adding the code from the post of Ruslan's answer in the post above. The screenshot is still coming back the same.
Update 2:
I have got everything working or so it seemed. I am now receiving this error only sometimes and I'm not sure what the cause is. Ignore the CustomerID error that is because their credit balance is overdue.
Add reference to PX.Web.UI.dll from Acumatica's Bin folder or using PX.Web.UI; if you are writing code in the customization's Code Editor.
ControlHelper is a static helper class for making easier work with Acumatica's Web controls .
UPDATE 1
In the answer you have noted addition of the Image is done in the lookup of the Inventory Item Selector and add to the Grid the field of the SOLineExt. In your case you are adding it to the SOLine. Here is code which is doing that:
using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;
namespace ClassLibrary1
{
public class SOLineExt : PXCacheExtension<SOLine>
{
#region ThumbnailURL
public abstract class thumbnailURL : IBqlField
{ }
[PXString]
public string ThumbnailURL { get; set; }
#endregion
}
public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
{
public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
{
baseMethod?.Invoke(sender, e);
if(e.Row!=null)
{
var row = e.Row as SOLine;
if (row.InventoryID != null)
{
InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
{
if(currentLineItem.StkItem==true)
{
InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
foreach (Guid fileID in files)
{
PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
{
row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
break;
}
}
}
else
{
NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
foreach (Guid fileID in files)
{
PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
{
row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
break;
}
}
}
}
}
}
}
}
}
As you can see I have added the ThumbnailURL directly to SOLine.
Also now it's needed to create instance of the InventoryItemMaint or NonStockItemMaint depending on the Item Type(Stock/NonStock).
As a result you should get this:
Related
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.CR;
using PX.Objects.TX;
using PX.Objects.IN;
using PX.Objects.EP;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.SO;
using PX.TM;
using SOOrder = PX.Objects.SO.SOOrder;
using SOLine = PX.Objects.SO.SOLine;
using PX.CS.Contracts.Interfaces;
using PX.Data.DependencyInjection;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Objects.PM;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AP.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects;
using PX.Objects.PO;
using PX.Objects.CT;
using PX.Data.EP;
namespace PX.Objects.PO
{
public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
{
#region Event Handlers
[Serializable]
public class ProjectFilter : IBqlTable
{
#region ContractID
public abstract class contractID : PX.Data.IBqlField { }
//[PXDefault(typeof(PMProject.contractID))]
[PXUIField(DisplayName = "Project ID")]
[Project(DescriptionField = typeof(PMProject.contractCD))]
public int? ContractID { get; set; }
#endregion
#region ProjectTaskID
public abstract class projectTaskID : PX.Data.BQL.BqlInt.Field<projectTaskID> { }
protected Int32? _ProjectTaskID;
[ProjectTask(typeof(PMProject.contractID), AlwaysEnabled = true, DirtyRead = true, IsKey = true)]
public virtual Int32? ProjectTaskID
{
get
{
return this._ProjectTaskID;
}
set
{
this._ProjectTaskID = value;
}
}
#endregion
}
//PXSelect<PMCostBudget, Where<PMCostBudget.projectID, Equal<Current<PMProject.contractID>>, And<PMCostBudget.type, Equal<GL.AccountType.expense>,
// And<Where<Current<CostBudgetFilter.projectTaskID>, IsNull, Or<Current<CostBudgetFilter.projectTaskID>, Equal<PMCostBudget.projectTaskID>>>>>>,
// OrderBy<Asc<PMCostBudget.projectID, Asc<PMCostBudget.projectTaskID, Asc<PMCostBudget.inventoryID, Asc<PMCostBudget.costCodeID, Asc<PMCostBudget.accountGroupID>>>>>>>(this);
//PXDelegateResult delResult = new PXDelegateRes
public PXFilter<ProjectFilter> projectfilter;
[PXFilterable]
[PXCopyPasteHiddenView]
public PXSelect<PMCostBudget,
Where<PMCostBudget.projectID, Equal<Current<ProjectFilter.contractID>>,
//And<PMCostBudget.projectTaskID, Equal<Current<ProjectFilter.projectTaskID>>,
//And<PMProject.locationID, Equal<Current<POOrder.vendorLocationID>>,
And<PMCostBudget.type, Equal<GL.AccountType.expense>>>> getCostBudget;
// public PXOrderedSelect<POOrder, POLine, Where<POLine.orderType, Equal<Current<POOrder.orderType>>, And<POLine.orderNbr, Equal<Optional<POOrder.orderNbr>>>>, OrderBy<Asc<POLine.orderType, Asc<POLine.orderNbr, Asc<POLine.sortOrder, Asc<POLine.lineNbr>>>>>> Transactions;
// PX.Objects.PM.PMProject project = PXSelect<PM.PMProject, Where<PM.PMProject.contractID, Equal<Required<PM.PMProject.contractID>>>>.Select(this, location.Current.VDefProjectID);
//if (project != null)
public PXAction<POOrder> AddProjectCostBudget;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Add Project Cost Budget")]
public virtual IEnumerable addProjectCostBudget(PXAdapter adapter)
{
if (getCostBudget.AskExt() == WebDialogResult.OK)
{
return addSelCostBudget(adapter);
}
return adapter.Get();
}
public PXAction<POOrder> AddSelCostBudget;
[PXUIField(DisplayName = "Add", Visible = false)]
[PXButton(CommitChanges = true)]
public virtual IEnumerable addSelCostBudget(PXAdapter adapter)
{
//Base.Transactions.Cache.ForceExceptionHandling = true;
foreach (PMCostBudget cost in getCostBudget.Cache.Cached)
{
//var costExt = cost.GetExtension<PMBudgetExt>();
if (cost.Selected == true)
{
POLine newline = Base.Transactions.Insert();
newline.ProjectID = cost.ProjectID;
newline.TaskID = cost.ProjectTaskID;
newline.CostCodeID = cost.CostCodeID;
newline.InventoryID = cost.InventoryID;
newline.UOM = cost.UOM;
Base.Transactions.Cache.Update(newline);
Base.Transactions.Update(newline);
}
}
//getCostBudget.Cache.Clear();
return adapter.Get();
}
//public override void Initialize()
//{
// base.Initialize();
// AddProjectCostBudget.SetEnabled(false);
//}
//protected virtual void PMCostBudget_ProjectTaskID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
//{
// PMCostBudget row = e.Row as PMCostBudget;
// if (row == null) return;
// if (!(e.NewValue is Int32)) return;
// if (e.NewValue != null)
// {
// PXResultset<INLocation> projectLocations = PXSelectReadonly<INLocation,
// Where<INLocation.projectID, Equal<Required<INLocation.projectID>>,
// And2<Where<INLocation.taskID, IsNull>, Or<INLocation.taskID, Equal<Required<INLocation.taskID>>>>>>.Select(Base, row.ProjectID, e.NewValue);
// string taskCD = null;
// PMTask task = PXSelect<PMTask, Where<PMTask.taskID,
// Equal<Required<PMTask.taskID>>>>.Select(Base, row.TaskID);
// if (task != null)
// {
// taskCD = task.TaskCD;
// }
// else
// {
// sender.RaiseExceptionHandling<PMCostBudget.projectTaskID>(row, taskCD, new PXSetPropertyException(Messages.ProjectTaskIsNotAssociatedWithAnyInLocation, PXErrorLevel.Warning));
// }
// }
//}
//protected virtual void PMCostBudget_ProjectTaskID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
//{
// PMCostBudget cost = e.Row as PMCostBudget;
// if (cost == null) return;
// PMTask task = PXSelect<PMTask,
// Where<PMTask.projectID, Equal<Current<ProjectFilter.contractID>>,
// And<PMTask.isDefault, Equal<True>>>>.Select(Base, cost.ProjectID, cost.ProjectTaskID);
// if (task == null) return;
// sender.SetValue<PMCostBudget.projectTaskID>(cost, task.TaskID);
//}
#endregion
}
}
I had created a pop-up panel to insert Project Cost budget into POLines in Purchase Order screen. every time I want to select and insert, It gives this error
Error: An error occurred during processing of the field Project Task: Error: 'Project Task' cannot be found in the system.
The code snippet of my view:[
[Serializable]
public class ProjectFilter : IBqlTable
{
#region ContractID
public abstract class contractID : PX.Data.IBqlField { }
//[PXDefault(typeof(PMProject.contractID))]
[PXUIField(DisplayName = "Project ID")]
[Project(DescriptionField = typeof(PMProject.contractCD))]
public int? ContractID { get; set; }
#endregion
#region ProjectTaskID
public abstract class projectTaskID : PX.Data.BQL.BqlInt.Field<projectTaskID> { }
protected Int32? _ProjectTaskID;
[ProjectTask(typeof(PMProject.contractID), AlwaysEnabled = true, DirtyRead = true, IsKey = true)]
public virtual Int32? ProjectTaskID
{
get
{
return this._ProjectTaskID;
}
set
{
this._ProjectTaskID = value;
}
}
#endregion
}
public PXFilter<ProjectFilter> projectfilter;
[PXFilterable]
[PXCopyPasteHiddenView]
public PXSelect<PMCostBudget,
Where<PMCostBudget.projectID, Equal<Current<ProjectFilter.contractID>>,
And<PMCostBudget.projectTaskID, Equal<Current<ProjectFilter.projectTaskID>>,
And<PMCostBudget.type, Equal<GL.AccountType.expense>>>>> getCostBudget;
]1 this is the error image
The ProjectTask attribute expects a reference to the currently selected project; you need to use ProjectFilter.projectID instead of PMProject.projectID
Build 18.203.0006
Page: AP301000
Good day, I have extended the APRegister Class by adding 2 new checkbox fields. I want to iterate through al the APTran transactions and look for suIDs that start with FBL and GAS. If I find them the new tick boxes should tick.
Currently, the fields(tick boxes) do not save to the database. I am not sure how to tell Acumatica the APRegisterExt has updated.
APInvoiceEntry_Extension:
namespace PX.Objects.AP
{
public class APRegisterExt : PXCacheExtension<PX.Objects.AP.APRegister>
{
#region UsrGroupAEmail
[PXDBBool]
[PXUIField(DisplayName="GroupA Email")]
public virtual bool? UsrGroupAEmail { get; set; }
public abstract class usrGroupAEmail : IBqlField { }
#endregion
#region UsrGroupBEmail
[PXDBBool]
[PXUIField(DisplayName="GroupB Email")]
public virtual bool? UsrGroupBEmail { get; set; }
public abstract class usrGroupBEmail : IBqlField { }
#endregion
}
}
APInvoiceEntry_Extension:
namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
#region Event Handlers
protected void APInvoice_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
APInvoice invoice = e.Row as APInvoice;
if (invoice == null) return;
var apRX = invoice.GetExtension<APRegisterExt>();
PXResultset<APTran> Tlist = PXSelectJoin<APTran,
LeftJoin<POReceiptLine,
On<POReceiptLine.receiptNbr, Equal<APTran.receiptNbr>,
And<POReceiptLine.lineNbr, Equal<APTran.receiptLineNbr>>>>,
Where<
APTran.tranType, Equal<Current<APInvoice.docType>>,
And<APTran.refNbr, Equal<Current<APInvoice.refNbr>>>>,
OrderBy<
Asc<APTran.tranType,
Asc<APTran.refNbr,
Asc<APTran.lineNbr>>>>>.Select(Base);
apRX.UsrGroupBEmail = false;
apRX.UsrGroupAEmail = false;
foreach (APTran item in Tlist)
{
if (item.SubID.Value.ToString().StartsWith("FBL") || item.SubID.Value.ToString().StartsWith("GAS"))
{
apRX.UsrGroupBEmail = true;
cache.SetValue<APRegisterExt.usrGroupBEmail>(e.Row, true);
}
else
{
apRX.UsrGroupAEmail = true;
}
}
}
#endregion
}
}
Can someone please show me the correct way of saving the data to the new tick boxes so that cache updates.
Consider moving the logic to APRegister_RowPersisting.
Importantly, APTran.subID is an Int dataType.
Read instead the Sub table/DAC during a For Loop of
Base.Transactions.Select() to detect SubCD startsWith FBL or GAS.
foreach(APTran item in Base.Transaction.Select())
{
Sub sub = PXSelect<Sub,
Where<Sub.subID, Equal<Required<Sub.subID>>>>
.Select(graph, item.SubID);
if (item.SubCD.StartsWith("FBL") ||
item.SubCD.StartsWith("GAS"))
{
apRX.UsrGroupBEmail = true;
}
else
{
apRX.UsrGroupAEmail = true;
}
}
To be complete, you may also need to reset both flags during APTran_SubID_FieldUpdated regardless of the changed value:
protected void APTran_SubID_FieldUpdated(PXCache sender,
PXFieldUpdatedEventArgs e, PXFieldUpdated del)
{
del?.Invoke(sender,e);
var apRX = Base.Document.Current.GetExtension<APRegisterExt>();
apRX.UsrGroupBEmail = false;
apRX.UsrGroupAEmail = false;
}
I have a requirement to have a field on SalesOrder screen and the same field should appear on Shipment screen also for respective SalesOrder. And the user should be able to update these field on both the screen.
I created a bound field on Sales Order screen which user can save it. Then I created an unbound field on Shipment screen to show the text from Sales Order. For that I have written a SOShipment_RowSelected event and later for user to update it to the database, I have written SOShipment_RowUpdated. However, when I try to edit the field, it fires RowSelected event and it overwrites the editing and bring back in the same original value.
I have tried with SOShipment_ShipmentNbr_FieldUpdated & SOShipment_ShipmentNbr_FieldUpdating event but its not firing everytime.
Here is the code for Cache extension-
public class SOOrderExtension : PXCacheExtension<SOOrder>
{
#region UsrNotesText
[PXDBString(255)]
[PXUIField(DisplayName = "Pick List Notes")]
public virtual string UsrNotesText { get; set; }
public abstract class usrNotesText : IBqlField { }
#endregion
}
public class SOShipmentExtension : PXCacheExtension<SOShipment>
{
#region UsrNotesText
[PXString(255)]
[PXUIField(DisplayName = "Pick List Notes")]
public virtual string UsrNotesText { get; set; }
public abstract class usrNotesText : IBqlField { }
#endregion
}
SOShipmentExtension code-
public class SOShipmentEntryExtension : PXGraphExtension<SOShipmentEntry>
{
PXSelect<SOOrder> soOrder;
protected virtual void SOShipment_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
if (e.Row != null)
{
SOOrder order = PXSelectJoin<SOOrder,
LeftJoin<SOOrderShipment, On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>,
LeftJoin<SOShipment, On<SOOrderShipment.shipmentNbr, Equal<SOShipment.shipmentNbr>>>>,
Where<SOShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>.Select(Base);
if (order != null)
{
SOOrderExtension orderExt = PXCache<SOOrder>.GetExtension<SOOrderExtension>(order);
SOShipment soShipment = Base.Document.Current;
SOShipmentExtension ext = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(soShipment);
ext.UsrNotesText = orderExt.UsrNotesText;
}
}
}
protected virtual void SOShipment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
SOShipment oldRow = (SOShipment)e.OldRow;
SOShipment newRow = (SOShipment)e.Row;
if (oldRow != null || newRow != null)
{
SOShipmentExtension oldExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(oldRow);
SOShipmentExtension newExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(newRow);
if (oldExt.UsrNotesText != newExt.UsrNotesText)
{
{
SOOrder order = PXSelectJoin<SOOrder,
LeftJoin<SOOrderShipment, On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>,
LeftJoin<SOShipment, On<SOOrderShipment.shipmentNbr, Equal<SOShipment.shipmentNbr>>>>,
Where<SOShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>.Select(Base);
soOrder.Current = order;
if (order != null)
{
SOOrderExtension orderExt = PXCache<SOOrder>.GetExtension<SOOrderExtension>(order);
orderExt.UsrNotesText = newExt.UsrNotesText;
soOrder.Update(order);
}
}
}
}
}
}
Any suggestions?
The trick is to initialize UsrNotesText elsewhere.
You can use PXDefault attribute:
[PXDefault(typeof(Search<SOOrderExtension.usrNotesText, Where< [...] >>))]
Or FieldDefaulting event handler:
public void SOShipment_UsrNotesText_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = [...]
}
Sometimes you also want to re-initialize when user changes key fields that are not re-triggering the default.:
public void SOShipment_ShipmentNbr_FieldUpdated(PXCache sender, PXFieldDefaultingEventArgs e)
{
SOShipment shipment = e.Row as SOShipment;
if (shipment != null)
{
SOShipmentExtension shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(shipment);
if (shipmentExt != null)
{
shipmentExt.UsrNotesText = [...];
}
}
}
In such case manually re-triggering FieldDefaulting event with RaiseFieldDefaulting is often a better option.
However method you choose to initialize avoid setting the field value in RowSelected because that event is called at times when you don't want to initialize the custom field.
We have a custom processing screen that is updating a custom field called UsrDateNotified in the ARTran table where the UsrDateNotified is prior to the RevisionDateReceived in a custom table ItemBaseDocument. We also need to update the UsrDateNotified field in table ItemBaseDocument which is linked to the InventoryID in ARTran. Our current code below validates for updating the ARTran table, but we are struggling with how to also update the related ItemBaseDocument for the selected ARTran records. What is the right approach for this scenario?
using System;
using System.Collections;
using System.Linq;
using PX.Data;
using PX.SM;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.IN;
namespace DocCenter
{
public class UpdateLastNotified : PXGraph<UpdateLastNotified>
{
public PXFilter<UpdateLastNotifiedFilter> MasterView;
public PXCancel<UpdateLastNotifiedFilter> Cancel;
[PXFilterable]
public PXSelect<ARTran> DetailsView;
public UpdateLastNotified()
{
Cancel.SetCaption("Clear Filter");
this.DetailsView.Cache.AllowInsert = false;
this.DetailsView.Cache.AllowDelete = false;
this.DetailsView.Cache.AllowUpdate = true;
}
protected virtual IEnumerable detailsView()
{
UpdateLastNotifiedFilter filter = MasterView.Current as UpdateLastNotifiedFilter;
PXSelectBase<ARTran> cmd = new PXSelectJoinOrderBy<ARTran,
InnerJoin<InventoryItem, On<ARTran.inventoryID, Equal <InventoryItem.inventoryID>>,
InnerJoin<ItemBaseDocument, On<InventoryItemExt.usrDocumentNumber, Equal<ItemBaseDocument.baseDocumentCode>>,
InnerJoin<Contact, On<ARTranExt.usrContactID, Equal<Contact.contactID>>>>>,
OrderBy<Asc<ARTran.tranDate>>>(this);
cmd.WhereAnd<Where<ContactExt.usrNotificationPriority,
Equal<Current<UpdateLastNotifiedFilter.notificationPriority>>>>();
cmd.WhereAnd<Where<ARTranExt.usrDateNotified,
Less<ItemBaseDocument.revisionDateReceived>>>();
if (filter.BaseDocumentCode != null)
{
cmd.WhereAnd<Where<InventoryItemExt.usrDocumentNumber,
Equal<Current<UpdateLastNotifiedFilter.baseDocumentCode>>>>();
}
return cmd.Select();
}
public PXAction<UpdateLastNotifiedFilter> Process;
[PXProcessButton]
[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Process")]
protected virtual IEnumerable process(PXAdapter adapter)
{
PXLongOperation.StartOperation(this, delegate()
{
foreach(ARTran tran in DetailsView.Select())
{
if (tran.Selected==true)
{
ARTranExt tranExt = tran.GetExtension<ARTranExt>();
ARInvoiceEntry tranEntry = new ARInvoiceEntry();
tranExt.UsrDateNotified = MasterView.Current.DateNotified;
tranEntry.Transactions.Update(tran);
tranEntry.Save.PressButton();
}
}
}
);
return adapter.Get();
}
[Serializable]
public class UpdateLastNotifiedFilter : IBqlTable
{
public static class NotificationPriority
{
public const string None = "N";
public const string Alert = "A";
public const string Express = "E";
public const string Shipment = "P";
public const string Subscription = "S";
}
#region NotificationPriority
public abstract class notificationPriority : PX.Data.IBqlField
{
}
[PXDBString(1, IsFixed = true)]
[PXDefault(NotificationPriority.None)]
[PXUIField(DisplayName = "Notification Type")]
[PXStringList(
new string[]
{
NotificationPriority.None,
NotificationPriority.Alert,
NotificationPriority.Express,
NotificationPriority.Shipment,
NotificationPriority.Subscription
},
new string[]
{
"None",
"Alert",
"Express",
"Shipment",
"Subscription"
})]
#endregion
#region BaseDocumentID
public abstract class baseDocumentCode : PX.Data.IBqlField
{
}
[PXString(50)]
[PXUIField(DisplayName="Document Number")]
[PXSelector(typeof(DocCenter.ItemBaseDocument.baseDocumentCode))]
public virtual String BaseDocumentCode
{
get;
set;
}
#endregion
#region DateNotified
public abstract class dateNotified : PX.Data.IBqlField
{
}
[PXDBDate()]
[PXDefault(typeof(AccessInfo.businessDate))]
[PXUIField(DisplayName = "Date Notified")]
public DateTime? DateNotified { get; set; }
#endregion
}
}
}
Your best bet would be to create a view that selects ItemBaseDocument.
PXSelect<ItemBaseDocument> ViewName;
In your for loop of your action button, you will want to create a new ItemBaseDocument object and set it equal to the corresponding ItemBaseDocument row entry. You can then update the date of this object, and when you execute your Save.PressButton() action, that should save the updates to that entry as well.
foreach(ARTran tran in DetailsView.Select())
{
if (tran.Selected==true)
{
ARTranExt tranExt = tran.GetExtension<ARTranExt>();
ARInvoiceEntry tranEntry = new ARInvoiceEntry();
tranExt.UsrDateNotified = MasterView.Current.DateNotified;
tranEntry.Transactions.Update(tran);
tranEntry.Save.PressButton();
//Target Added Code
ItemBaseDocument doc = PXSelect<ItemBaseDocument, Where<ItemBaseDocument.inventoryID,
Equal<Required<ARTran.inventoryID>>>>.Select(tran.InventoryID);
doc.UsrDateNotified = MasterView.Current.DateNotified;
}
}
Disclaimer: There may be a syntax error in the added code above. If there is, please let me know and I will fix it.
May I ask for your guidance here, my problem is I added a Branch Filter on the Create Requisition(RQ504000) screen, I tried to override the RQRequestProcessing Class but it just don't work. I also tried adding a WhereAnd on the Records view upon field updated but it also does not work. Any suggestion is greatly appreciated thanks.
I propose you following solution:
public class RQRequestSelectionExt : PXCacheExtension<RQRequestSelection>
{
#region AllocatedAmount2
public abstract class usrBranchID : IBqlField
{
}
[PXDBInt]
[PXUIField(DisplayName = "Branch ID")]
[PXDefault(2)]
[Branch]
public int? UsrBranchID { get; set; }
#endregion
}
public class RQRequestProcessExt : PXGraphExtension<RQRequestProcess>
{
[PXFilterable(new System.Type[] { })]
public RQRequestProcess.RQRequestProcessing Records;
public IEnumerable records()
{
var currentFilter = Base.Filter.Current;
var filterExt = currentFilter.GetExtension<RQRequestSelectionExt>();
var newList = Base.Records.Select();
ArrayList result = new ArrayList();
foreach (PXResult<RQRequestLineOwned> listItme in newList)
{
var row = listItme.GetItem<RQRequestLineOwned>();
if (filterExt.UsrBranchID != null)
{
if (row.BranchID == filterExt.UsrBranchID)
{
result.Add(row);
}
}
else
{
result.Add(row);
}
}
return result;
}
}
Another one, you can try to play with WhereAnd, but I for myself wasn't very successful with it.