General X++ Development

How do I declare class-level variables in an extension class?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I declare class-level variables in an extension class?

SSunny Vasty75 reputation · answered Aug 13, 2026

Yes. Class augmentation can add instance state to the effective class.

X++
[ExtensionOf(classStr(MyClass))]
final class MyClass_XppForge_Extension
{
    private int xppForgeCounter;

    public void xppForgeIncrementCounter()
    {
        xppForgeCounter++;
    }
}

That value belongs to that object instance. It is not persisted anywhere.

One thing I would not do is use generic names like myCounter in real extension code. Extension members share the effective class namespace, so give new methods and variables names that are unlikely to collide with Microsoft or another extension later.