Acumatica Can't access Extension DAC from BLC - acumatica

Im trying to assign variables to my graph from InventoryItem and InventoryItemExt.
(First Column is a InventoryItem Selector)
I've also tried using another PXSelectorAttribute, doing so I received an attribute error on runtime
InventoryItemExt item2 = PXSelectorAttribute.Select<atcProjectLinesTable.itemNumber>(cache,line) as InventoryItemExt;

Your FieldUpdated handler was declared for the atcProjectLinesTable DAC - cache parameter represents PXCache instance created for the atcProjectLinesTable DAC, not InventoryItem. I would assume the issue to happen when the system invokes cache.GetExtension<InventoryItemExt>(item).
Try replacing the following line
InventoryItemExt item2 = cache.GetExtension<InventoryItemExt>(item);
with
InventoryItemExt item2 = item.GetExtension<InventoryItemExt>();

Related

How can I set the LocationID on the 'Create Shipment' process from the Sales Orders screen?

I have a process that creates records in the Sales Orders screen's Details grid based on two Header user fields: SiteID (Warehouse) and LocationID.
When the 'Create Shipment' process is initiated, the shipment is created which contains the SiteID in the Sales Orders grid - but since there is no locationID in the grid, this 'Create Shipment' process uses some default(?) LocationID, where I'd like to use the Header User field's LocationID.
My question is, how would I intercept this process to set the LocationID to something other than what it's defaulting to?
Thanks...
Update:
Using the virtual method:
SetShipmentFieldsFromOrder(SOOrder order, SOShipment shipment, Nullable<Int32> siteID, Nullable<DateTime> shipDate, String operation, SOOrderTypeOperation orderOperation, Boolean newlyCreated, SetShipmentFieldsFromOrderDelegate baseMethod)
I don't see any way to set the grid value for LocationID (i.e., there is no SOShipLine record to set a value in the virtual method. How would I do this?
There's a virtual method on the SOShipmentEntry graph called SetShipmentFieldsFromOrder, you can override that to update the CustomerLocationID as needed. The create shipment action calls SOShipmentEntry.CreateShipment which inserts the shipment and then calls the SetShipmentFieldsFromOrder method.
The system should be pulling the SOShipment.CustomerLocationID from the SOOrder.CustomerLocationID field by default though.
I believe the question is about defaulting of warehouse locations into the shipment lines and allocations rather than customer locations
Currently, shipment line selects location(s) by the following way
Originally (SelectLocationStatus), it selects location based on their pick priority (smaller value means higher priority)
After this method, the ResortStockForShipmentByDefaultItemLocation is executed. This method puts the default issue location for the item-warehouse combination (InItemSite) at the top of this list regardless of its pick priority.
I believe you should override this method to put the needed location to the top of the list instead of (or ahead of) the default issue location. Here is the code of this method of the SOShipmentEntry class for reference:
protected virtual void ResortStockForShipmentByDefaultItemLocation(SOShipLine newline, List<PXResult> resultset)
if (INSite.PK.Find(this, newline.SiteID)?.UseItemDefaultLocationForPicking != true)
return;
var dfltShipLocationID = INItemSite.PK.Find(this, newline.InventoryID, newline.SiteID)?.DfltShipLocationID;
if (dfltShipLocationID == null)
return;
var listOrderedByDfltShipLocationID = resultset.OrderByDescending(
r => PXResult.Unwrap<INLocation>(r).LocationID == dfltShipLocationID).ToList();
resultset.Clear();
resultset.AddRange(listOrderedByDfltShipLocationID);
}
Important! If we are talking about 21R2 version, there is the "Project-Specific Inventory" (materialManagement) feature which has its own extension of the SOShipmentEntry where some of the shipment creation methods (including the SelectLocationStatus) are overridden. The ResortStockForShipmentByDefaultItemLocation is not overridden, but if the customer uses this feature, I suggest to extend this extension rather than base SOSHipmentEntry:
namespace PX.Objects.PM.MaterialManagement
{
public class SOShipmentEntryMaterialExt : PXGraphExtension<SOShipmentEntry>

How to add a column to the grid that shows value from another screen in Acumatica?

I'm new to Acumatica, could you please help me? I have too screens IN202500 (stock items) and SO301000(sales orders). I added a field to stock items and now I need to show a value from that field in grid column of sale orders for each stock items. I suppose that I need to use PXDefault attribute for this?
There are a number of ways you can do this. I'll provide 3 possibilities.
If your View used by the grid contains InventoryItem, you may be able simply to select your custom field from InventoryItem and add it directly to the screen. I'll assume this is not an option or you likely would have found it already.
Create a custom field in a DAC extension on SOLine where you add your custom field as unbound (PXString, not PXDBString) and then use PXDBScalar or PXFormula to populate it. I haven't used PXDBScalar or PXFormula to retrieve a value from a DAC Extension, so I'll leave it to you to research. I do know this is super easy if you were pulling a value directly from InventoryItem, so worth doing the research.
Create as an unbound field as in #2, but populate it in the SOLine_RowSelecting event. This is similar to JvD's suggestion, but I'd go with RowSelecting because it is the point where the cache data is being built. RowSelected should be reserved, in general, for controlling the UI experience once the record is already in the cache. Keep in mind that this will require using a new PXConnectionScope, as Acuminator will advise and help you add. (Shown in example.) In a pinch, this is how I would do it if I don't have time to sort out the generally simpler solution provided as option 2.
Code for Option 3:
#region SOLine_RowSelecting
protected virtual void _(Events.RowSelecting<SOLine> e)
{
SOLine row = (SOLine)e.Row;
if (row == null)
{
return;
}
using (new PXConnectionScope())
{
SOLineExt rowExt = row.GetExtension<SOLineExt>();
InventoryItem item = SelectFrom<InventoryItem>
.Where<InventoryItem.inventoryID.IsEqual<#P.AsInt>>
.View.Select(Base, row.InventoryID);
InventoryItemExt itemExt = item.GetExtension<InventoryItemExt>();
rowExt.UsrSSMyDatAField = itemExt.UsrSSMyDataField;
}
}
#endregion

Acumatica Link Between CROpportunity and SOOrders - Generic Inquiry

R2 was recently released and there is a need to get the relationships between CROpportunity and SOOrder to add to the Sales Order entry screen (the Generic Inquiry). What is the relationship between both of these DACs? Are there other DACs which need to be included instead of a direct link?
1st Try
I have tried using CROpportunity to FSServiceOrder and then FSServiceOrder to SOOrder using the below:
CROpportunity/FSService Order on SOID/SOID
FSServiceOrder/SOOrder on refNbr/sourceRefNbr
2nd Try
I also tried doing a direct relationship between CROpportunity to SOOrder using:
CROpportunity/SOOrder on externalRef/sourceRefNbr
Using this, also:
CROpportunity/SOOrder on externalRef/externalRef
To obtain the relationship between Opportunities and Sales Orders try the pattern below. Recent versions of Acumatica now allow a 1 to many relationship between opportunities and sales orders.
This is the SQL link to help clarify the screen shots for the GI.
select o.CompanyID, o.OrderDate, o.OrderNbr, r.RefNoteID, r.Role, p.OpportunityID
from SOOrder o
inner join CRRelation r on o.NoteID = r.RefNoteID and r.CompanyID = o.CompanyID
inner join CROpportunity p on p.NoteID = r.TargetNoteID and r.Role = 'SR' and p.CompanyID = r.CompanyID

How to Append Acumatica DAC attribute [PXEmailSource]

I want to know the best way to append the DAC attributes..Please note I need Appending method for DAC Attributes not DAC Field Attributes.
Specifically I need to append [PXEMailSource] to some of the existing DACs
Eg: PX.Objects.IN.INRegister
What is the best way to do it ...?
Any helps regarding this will be highly appreciated
You can change the attribute of the DAC using PXSubstituteAttribute
Note from Acumatica Framework Development Guide(page 95)
PXSubstitute Attribute
Indicates that the derived DAC should replace its base DACs in a specific graph or all graphs.
• public Type GraphType
Gets or sets the specific graph in which the derived DAC replaces base DACs.
• public Type ParentType
Gets or sets the base DAC type up to which all types in the inheritance
hierarchy are substituted with the derived DAC. By default, the property
has the null value, which means that all base DACs are substituted with the
derived DAC
Remarks
The attribute is placed on the definition of a DAC that is
derived from another DAC. The attribute is used primarily to make the
declarative references of the base DAC in definitions of calculations
and links from child objects to parent objects be interpreted as the
references of the derived DAC.
Below is the example how to use Attribute on INRegister DAC.
[PXPrimaryGraph(new Type[]
{
typeof(INReceiptEntry),
typeof(INIssueEntry),
typeof(INTransferEntry),
typeof(INAdjustmentEntry),
typeof(KitAssemblyEntry),
typeof(KitAssemblyEntry)
}, new Type[]
{
typeof(Where<INRegister.docType, Equal<INDocType.receipt>>),
typeof(Where<INRegister.docType, Equal<INDocType.issue>>),
typeof(Where<INRegister.docType, Equal<INDocType.transfer>>),
typeof(Where<INRegister.docType, Equal<INDocType.adjustment>>),
typeof(Select<INKitRegister, Where<INKitRegister.docType, Equal<INDocType.production>, And<INKitRegister.refNbr, Equal<Current<INRegister.refNbr>>>>>),
typeof(Select<INKitRegister, Where<INKitRegister.docType, Equal<INDocType.disassembly>, And<INKitRegister.refNbr, Equal<Current<INRegister.refNbr>>>>>)
})]
[INRegisterCacheName("Receipt")]
[Serializable]
[PXSubstitute(GraphType = typeof(REQUIREDGRAPH_WHERE_SHOULD_BE_SUBSTITED))]
[PXEMailSource]
public class INRegisterExt: INRegister
{
//...
}

How do I prevent SOLineSplit and INItemPlan from deleting when Qty = 0?

I noticed that when the quantity of a SOLine is zero, there are no SOLineSplit or INItemPlan records available for that line. The second the quantity is greater than 0, the system makes those records, and if the qty is set back to 0, the records are deleted.
Is there a way to prevent the SOLineSplit and INItemPlan objects from deleting when a record is set to 0 quantity?
Is there a way to still have the system create an SOLineSplit and INItemPlan if the SOLine is initially created with a 0 quantity?
The reason for the question is that a customer wants the system to lock the SOLine after a certain point, but also allow for the Qty to be adjusted from another screen. Since this is not directly changing the value on the SOLine screen, this isn't triggering the events to create the split and plan.
I have tried creating an instance of SOOrderEntry in the custom screen as follows:
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
//Also tried graph.Transactions.Current = line, but did not work
graph.Transactions.Update(line);
graph.Actions.PressSave();
Doing that keeps resulting in a null object reference error:
Error: An error occurred during processing of the field OrderQty : Object reference not set to an instance of an object..
System.NullReferenceException: Object reference not set to an instance of an object.
at PX.Objects.SO.SOOrderEntry.SOLine_OrderQty_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) ...
I think the problem with your statement in using SOOrderEntry is you are not truly loading the order in the graph to update it correctly. After you create the graph instance and before the transaction update, you should load the document header like this...
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
graph.Document.Current = graph.Document.Search<SOOrder.orderNbr>(line.OrderNbr, line.OrderType);
if(graph.Document.Current == null)
{
return;
}
graph.Transactions.Update(line);
graph.Actions.PressSave();
As for controlling how the plan and split records are entered from SOOrderEntry... The entries are controlled through the attributes on PlanID. The cache attached is where this gets added on SOOrderEntry...
[PXMergeAttributes(Method = MergeMethod.Append)]
[SOLineSplitPlanID(typeof(SOOrder.noteID), typeof(SOOrder.hold), typeof(SOOrder.orderDate))]
protected virtual void SOLineSplit_PlanID_CacheAttached(PXCache sender)
{
}
You can make your own graph extension of Sales order and replace the attribute with your own version of SOLineSplitPlanID... it might be a battle for you as I am not sure why you would want the plan record to exist when zero qty to plan.

Resources