0
votes

I thought that a previous question I had listed was working fine, until I noticed that I needed the InventoryCD not the InventoryID. The inventoryCD is not found on the KitAssembly screen (IN307000) or DAC. So, I have created a new Usr field called UsrInventoryCD and it pulls the same InventoryCD when the KitAssemblyID field is populated. This is working correctly. Next I want to take this field and pass the value into report parameters from a button. This is what I have so far:

protected void INKitRegister_UsrInventoryCD_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            var item = (INKitRegister)e.Row;
            if (item == null) return;
            var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
            if (invitem != null)
            {
                e.ReturnValue = invitem.InventoryCD;
            }
        }

public class KitAssemblyEntry_Extension:PXGraphExtension<KitAssemblyEntry>
  {
  public override void Initialize()
    {
        Report.AddMenuAction(Report1);
        Report.AddMenuAction(Report2);
        Report.AddMenuAction(Report3);
        Report.AddMenuAction(Report5);
        Report.AddMenuAction(Report6);
        Report.MenuAutoOpen = true;
    }

    #region Event Handlers

    public PXAction<INKitRegister> Report;
    [PXButton]
    [PXUIField(DisplayName = "Go To", MapEnableRights = PXCacheRights.Select)]
    protected void report()
    { }

    public PXAction<INKitRegister> Report1;
    [PXUIField(DisplayName = "Report1", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report1(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
  var style = item.GetExtension<INKitRegisterExt>().UsrInventoryCD;
  INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = style.ToString();
        throw new PXReportRequiredException(parameters, "IN610002", "Report1");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report2;
    [PXUIField(DisplayName = "Report2", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report2(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
  var style = item.GetExtension<INKitRegisterExt>().UsrInventoryCD;
  INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = style.ToString();
        throw new PXReportRequiredException(parameters, "IN610003", "Report2");
        }
     return adapter.Get();
    }


      public PXAction<INKitRegister> Report3;
    [PXUIField(DisplayName = "Report3", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report3(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
  var style = item.GetExtension<INKitRegisterExt>().UsrInventoryCD;
  INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = style.ToString();
        throw new PXReportRequiredException(parameters, "IN610001", "Report3");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report4;
    [PXUIField(DisplayName = "Report4", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report4(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
  var style = item.GetExtension<INKitRegisterExt>().UsrInventoryCD;
  INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = style.ToString();
        throw new PXReportRequiredException(parameters, "IN610005", "Report4");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report5;
    [PXUIField(DisplayName = "Report5", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report5(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
  var style = item.GetExtension<INKitRegisterExt>().UsrInventoryCD;
  INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = style.ToString();
        throw new PXReportRequiredException(parameters, "IN610006", "Report5");
        }
     return adapter.Get();
    }
    #endregion

  }

It compiles just fine but I am getting this error when trying to click on one of the report buttons that have been added to the screen.

An unhandled exception has occurred in the function 'MoveNext'. Please see the trace log for more details.

And this is the trace log:

An unhandled exception has occurred in the function 'MoveNext'. Please see the trace log for more details. 

System.NullReferenceException: Object reference not set to an instance of an object. 
   at PX.Objects.IN.KitAssemblyEntry_Extension.report1(PXAdapter adapter) 
   at PX.Data.PXAction`1.a(PXAdapter A_0) 
   at PX.Data.PXAction`1.d__31.MoveNext() 
   at PX.Data.PXAction`1.d__31.MoveNext() 
   at PX.Data.PXAction`1.d__31.MoveNext() 
   at PX.Data.PXAction`1.d__31.MoveNext() 
   at PX.Web.UI.PXBaseDataSource.tryExecutePendingCommand(String viewName, String[] sortcolumns, Boolean[] descendings, Object[] searches, Object[] parameters, PXFilterRow[] filters, DataSourceSelectArguments arguments, Boolean& closeWindowRequired, Int32& adapterStartRow, Int32& adapterTotalRows) 
   at PX.Web.UI.PXBaseDataSource.ExecuteSelect(String viewName, DataSourceSelectArguments arguments, PXDSSelectArguments pxarguments) 

Here is the previous question I have asked if that pertains any information that might be useful: Acumatica - Add Reports dropdown to Kit Assembly Screen

1
I have changed the code above to fit a better DAC extension pull that I found in some documentation. I am still getting the same error however and I don't know what I'm missing, I do know that this normally happens when it wants to return null or it is not found. This is not being pulled from the database itself, I mean it can be if save is hit, but it does not make a difference. I still get the same error either way.Dane

1 Answers

0
votes

I went a different direction fix this one but just using a PXSelect instead of a custom field. I deleted the custom field and used the code below. The answer is as follows and working:

public class KitAssemblyEntry_Extension:PXGraphExtension<KitAssemblyEntry>
  {
  public override void Initialize()
    {
        Report.AddMenuAction(Report1);
        Report.AddMenuAction(Report2);
        Report.AddMenuAction(Report3);
        Report.AddMenuAction(Report5);
        Report.AddMenuAction(Report6);
        Report.MenuAutoOpen = true;
    }

    #region Event Handlers

    public PXAction<INKitRegister> Report;
    [PXButton]
    [PXUIField(DisplayName = "Go To", MapEnableRights = PXCacheRights.Select)]
    protected void report()
    { }

    public PXAction<INKitRegister> Report1;
    [PXUIField(DisplayName = "Report1", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report1(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
      var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = invitem.InventoryCD.ToString();
        throw new PXReportRequiredException(parameters, "IN610002", "Report1");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report2;
    [PXUIField(DisplayName = "Report2", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report2(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
      var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = invitem.InventoryCD.ToString();
        throw new PXReportRequiredException(parameters, "IN610003", "Report2");
        }
     return adapter.Get();
    }


      public PXAction<INKitRegister> Report3;
    [PXUIField(DisplayName = "Report3", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report3(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
      var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = invitem.InventoryCD.ToString();
        throw new PXReportRequiredException(parameters, "IN610001", "Report3");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report4;
    [PXUIField(DisplayName = "Report4", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report4(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
      var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = invitem.InventoryCD.ToString();
        throw new PXReportRequiredException(parameters, "IN610005", "Report4");
        }
     return adapter.Get();
    }

      public PXAction<INKitRegister> Report5;
    [PXUIField(DisplayName = "Report5", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable report5(PXAdapter adapter)
    {
      INKitRegister item = Base.Document.Current;
      var invitem = (InventoryItem)PXSelect<InventoryItem,
            Where<InventoryItem.inventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>.Select(Base, item.InventoryID);
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["ItemNumber"] = invitem.InventoryCD.ToString();
        throw new PXReportRequiredException(parameters, "IN610006", "Report5");
        }
     return adapter.Get();
    }
    #endregion

  }