0
votes

I have been trying to add a Reports dropdown to the Kit Assembly screen (IN307000). We have custom reports that are based on the KitInventoryID that will be generated to print a tag essentially and these reports need to be added to the actions of the screen. I noticed that there is normally a transfer in most Report screens that will be used to transfer data so I did write my own statement at the top. Here is what I have so far:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN.Overrides.INDocumentRelease;
using PX.Objects.GL;
using PX.Objects.CM;
using System.Diagnostics;
using PX.Objects;
using PX.Objects.IN;

namespace PX.Objects.IN
{

  public class KitAssemblyEntry_Extension:PXGraphExtension<KitAssemblyEntry>
  {
  public PXSelect<INKitRegister, Where<INKitRegister.docType, Equal<Current<INKitRegister.docType>>, And<INKitRegister.kitInventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>> transfer;
  public override void Initialize()
    {
        Report.AddMenuAction(MasterTag);
        Report.MenuAutoOpen = true;
    }

    #region Event Handlers

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

    public PXAction<INKitRegister> MasterTag;
    [PXUIField(DisplayName = "Sample/Value Tag", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable masterTag(PXAdapter adapter)
    {
      INKitRegister doc = Base.transfer.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["DocType"] = this.transfer.Current.DocType;
        parameters["ItemNumber"] = this.transfer.Current.KitInventoryID.ToString();
        throw new PXReportRequiredException(parameters, "IN610004", "Sample/Value Tag");
        }

    }

    #endregion

  }


}

However, when I try to publish I get this error:

Building directory '\WebSiteValidationDomain\App_RuntimeCode\'.
\App_RuntimeCode\KitAssemblyEntry.cs(39): error CS1061: 'PX.Objects.IN.KitAssemblyEntry' does not contain a definition for 'transfer' and no extension method 'transfer' accepting a first argument of type 'PX.Objects.IN.KitAssemblyEntry' could be found (are you missing a using directive or an assembly reference?)
\App_RuntimeCode\KitAssemblyEntry.cs(39): error CS1061: 'PX.Objects.IN.KitAssemblyEntry' does not contain a definition for 'transfer' and no extension method 'transfer' accepting a first argument of type 'PX.Objects.IN.KitAssemblyEntry' could be found (are you missing a using directive or an assembly reference?)

I have also tried changing the INKitRegister doc = Base.transfer.Current;to INKitRegister doc = Base.Document.Current; but get this error:

\App_RuntimeCode\KitAssemblyEntry.cs(37): error CS0161: 'PX.Objects.IN.KitAssemblyEntry_Extension.masterTag(PX.Data.PXAdapter)': not all code paths return a value
\App_RuntimeCode\KitAssemblyEntry.cs(37): error CS0161: 'PX.Objects.IN.KitAssemblyEntry_Extension.masterTag(PX.Data.PXAdapter)': not all code paths return a value
1
Transfer is a DataView and according to the error unlike Document it's not a DataView of KitAssemblyEntry graph. While it may be used to fetch report parameter it's not part of the report subsystem. The second error about 'code paths' happens because you have an IEnumerable return type on masterTag method declaration but it is possible that the method definition returns nothing when doc is null. This is not allowed in C#, you must ensure all code paths of the method return a IEnumerable or null reference to satisfy the method contract. - Hugues Beauséjour
Adding "return adapter.Get()" at the bottom of the method will comply with the compiler check for the case where doc is null. - Hugues Beauséjour
That worked perfectly. We just have to modify our report. I will post the answer. Thanks! - Dane

1 Answers

0
votes

Here is the fixed coded and it is working properly.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN.Overrides.INDocumentRelease;
using PX.Objects.GL;
using PX.Objects.CM;
using System.Diagnostics;
using PX.Objects;
using PX.Objects.IN;

namespace PX.Objects.IN
{

  public class KitAssemblyEntry_Extension:PXGraphExtension<KitAssemblyEntry>
  {
  public PXSelect<INKitRegister, Where<INKitRegister.docType, Equal<Current<INKitRegister.docType>>, And<INKitRegister.kitInventoryID, Equal<Current<INKitRegister.kitInventoryID>>>>> transfer;
  public override void Initialize()
    {
        Report.AddMenuAction(MasterTag);
        Report.MenuAutoOpen = true;
    }

    #region Event Handlers

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

    public PXAction<INKitRegister> MasterTag;
    [PXUIField(DisplayName = "Sample/Value Tag", MapEnableRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable masterTag(PXAdapter adapter)
    {
      INKitRegister doc = Base.Document.Current;
        if (doc != null)
        {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters["DocType"] = this.transfer.Current.DocType;
        parameters["ItemNumber"] = this.transfer.Current.KitInventoryID.ToString();
        throw new PXReportRequiredException(parameters, "IN610004", "Sample/Value Tag");
        }
     return adapter.Get();
    }

    #endregion

  }


}