JvD
JvD

Reputation: 479

error CS0592: Attribute 'PXForeignReference' is not valid on this declaration type. It is only valid on 'class, property, indexer' declarations

Good day

I need to override the InventoryID field on the Purchase Orders screen. I want to make the field a Required field by overriding it on-screen level:

namespace PX.Objects.PO
{
  public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
  {
    #region Event Handlers
    
    
    [PXDefault]
    [POLineInventoryItem(Filterable = true)]
    [PXForeignReference(typeof(Field<inventoryID>.IsRelatedTo<InventoryItem.inventoryID>))]
    protected virtual void POLine_InventoryID_CacheAttached(PXCache cache)
    {
    
    }
    
    #endregion
  }
}

When I run the above I get the following error: \App_RuntimeCode\POOrderEntry.cs(45): error CS0592: Attribute 'PXForeignReference' is not valid on this declaration type. It is only valid on 'class, property, indexer' declarations.

Line 45 is [PXForeignReference(typeof(Field.IsRelatedTo<InventoryItem.inventoryID>))]

How would I go about fixing this error?

Upvotes: 0

Views: 523

Answers (1)

Brian Stevens
Brian Stevens

Reputation: 1941

I don't believe foreign reference is "legal" in the context of CacheAttached. You should be able to use PXMergeAttrubutes to add PXDefault without dropping the other attributes.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXDefault]
protected virtual void POLine_InventoryID_CacheAttached(PXCache cache){}

I did something similar to prevent use of a specific Item Class on SOLine.

#region SOLine_InventoryID_CacheAttached  
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<InventoryItem.itemClassID,
    NotEqual<Current<MySetup.PreventClassID>>>),"")]
protected virtual void SOLine_InventoryID_CacheAttached(PXCache sender) { }
#endregion

You also might consider PXUIRequiredAttribute if you want to define when it would be required. I believe this attribute can be used in a DAC Extension or CacheAttached.

#region MyDAC_AccountID_CacheAttached
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXDefault()]
[PXUIRequired(typeof(Where<Current<MyDAC.hold>, Equal<False>,
                        And<Current<MyBranchSetting.requireAccount>, Equal<True>>>))]
protected virtual void MyDAC_AccountID_CacheAttached(PXCache sender) { }
#endregion

Upvotes: 2

Related Questions