acumaticaacumatica-kb

Inventory Attributes to the Purchase Order Details Line Items


I am trying to add the attributes of a stock item to the PO Line in the Details Tab

These Attributes: Attributes in System Attributes in Database

For my problem i found this post on acumatica community, but i havent been able to transfer it to my problem. https://community.acumatica.com/develop-customizations-288/add-a-stock-item-attribute-to-the-sales-order-line-grid-6454

Here is my Code for the DAC Extension of POLine:

using PX.Common;
using PX.Data.BQL;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.CM.Extensions;
using PX.Objects.Common.Bql;
using PX.Objects.Common.Discount.Attributes;
using PX.Objects.Common.Discount;
using PX.Objects.Common;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.Objects.IN.Matrix.Interfaces;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.Objects.PO;
using PX.Objects.TX;
using PX.Objects;
using System.Collections.Generic;
using System;

namespace PX.Objects.PO
{
  public class POLineExt : PXCacheExtension<PX.Objects.PO.POLine>
  {
    #region UsrAttribute1

        [PXDBString(512, IsUnicode = true)]
        [PXUIField(DisplayName = "MATCHCODE")]
        public virtual string UsrAttribute1 { get; set; }
        public abstract class usrAttribute1 : BqlString.Field<usrAttribute1> { }


    #endregion
  }
}

And here for the Graph Extension POOrderEntry

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.Extensions;
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 SOOrder = PX.Objects.SO.SOOrder;
using SOLine = PX.Objects.SO.SOLine;
using PX.Data.DependencyInjection;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.LicensePolicy;
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.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects.Common.Bql;
using PX.Objects.Extensions.CostAccrual;
using PX.Objects.DR;
using PX.Data.WorkflowAPI;
using PX.Objects.Extensions;
using PX.Objects.Common.DAC;
using PX.Objects.Common.Scopes;
using PX.Objects.IN.Services;
using PX.Objects.Extensions.MultiCurrency;
using PX.Data.Description;
using PX.Objects;
using PX.Objects.PO;

namespace PX.Objects.PO
{
  public class POOrderEntry_Extension : PXGraphExtension<PX.Objects.PO.POOrderEntry>
  {
    #region Event Handlers
    protected virtual void POLine_InventoryID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
        {
            InvokeBaseHandler?.Invoke(sender, e);
            POLine row = (POLine)e.Row;
            if (row == null) return;
            CSAnswers CSAns = PXSelectJoin<CSAnswers,
                              InnerJoin<InventoryItem, On<InventoryItem.noteID, Equal<CSAnswers.refNoteID>>>,
                              Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>,
                              And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>
                              >>>.Select(Base, row.InventoryID, "MATCHCODE");
            if (CSAns != null)
            {
                POLineExt rowExt = row.GetExtension<POLineExt>();
                rowExt.UsrAttribute1 = CSAns.Value;
            }
        }
}
    #endregion
}

Case 1: In POOrderEntry with this:

rowExt.UsrAttribute1 = CSAns.Value; The compiler shows no error but when i try to open a PO the system gives the error “Invalid column name [POLine].[UsrAttribute1]”

Case 2: In POOrderEntry with this:

rowExt.usrAttribute1 = CSAns.Value; The following error appears:

\App_RuntimeCode\POOrderEntry.cs(60): error CS0572: 'usrAttribute1': cannot reference a type through an expression; try 'POLineExt.usrAttribute1' instead \App_RuntimeCode\POOrderEntry.cs(60): error CS0118: 'POLineExt.usrAttribute1' is a type but is used like a variable \App_RuntimeCode\POOrderEntry.cs(60): error CS0572: 'usrAttribute1': cannot reference a type through an expression; try 'POLineExt.usrAttribute1' instead


Solution

  • The problem is very simple, your UsrAttribute1 field is not in the database. Either you can change its attribute to PXDBString to PXString, but in this case the value won't be stored in the database, or you can add the field to the POLine table through the customization editor.

    enter image description here enter image description here