Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Pack variables

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a variable (db-field) from the form (InventTable.ItemId) that I need to store internally.

When I want to use this value it is not accessible.

I have in my class declared the following, but I seem to miss the setting from pack to InventTable.ItemId.

Does anyone know?

class A_FINMA40_Validate
{
    A_FINMA40_MandatoryFields   a_FINMA40_MandatoryFields;
    ClassBuild                  classBuild;
   container                   ItemId_Pack;

container pack()
{
    return [ItemId_Pack];
}

boolean unpack(container _packedClass)
{
    [ItemId_Pack] = _packedClass;
    return true;
}

}

Regards,

/Fredrik.

*This post is locked for comments

  • Verified answer
    Martin Dráb Profile Picture
    234,152 Most Valuable Professional on at
    RE: Pack variables

    All right then. Please don't forget to mark the helpful replies as verified answers.

  • Community Member Profile Picture
    on at
    RE: Pack variables

    I got it to work, thanks.

    The client wants this and are paying... :)

  • Verified answer
    Martin Dráb Profile Picture
    234,152 Most Valuable Professional on at
    RE: Pack variables

    There are many ways. For example, pass the active record to your class the active() method of your form datasource, e.g. validator.parmInventTable(inventTable).

    By the way, are you sure you should be playing with code generation? I would recommend learning basics first.

  • Community Member Profile Picture
    on at
    RE: Pack variables

    Suppose I am running the generated method

    private boolean FIN_testfb2()

    {

       EDIInventTable ediit;

    if (ediit.EDIZinc == 0)

    {

    info("Zinc Value is 0");

    return true;

    }

    else

    return false;

    }

    how can I access the active table in my form?

    The table name edit is just a name to get it approved.

    Whatever declaration am I to use to get the data and have the generated method go through?

    In the debug window I have the tables.

    + edit <recid = 0>

    - this new

    + ediinventtable <recid = 5637147591>

    + inventtable  <recid = 5637147591>

  • Suggested answer
    Martin Dráb Profile Picture
    234,152 Most Valuable Professional on at
    RE: Pack variables

    I'm able to use your code, if I fix the missing " in info("Zink value is 0.00);

    If it doesn't solve your problem, you have a bug in some code that you didn't show, e.g. in putting the code to AOT.

  • Community Member Profile Picture
    on at
    RE: Pack variables

    Ok, this is what I do.

    I have a maintenance form for my rules.

    This consists of the following fields.

    Table, Field, CodeId

    InventTable, GTIN, Test

    EDIInventTable,, EDIZINK, Test2

    ...

    I also have the possibility of adding X++ code per line, like this for line 2 above.

    if (ediinventtable.EDIZinc == 0)

    {

    info("Zink value is 0.00);

    return true;

    }

    else

    return false;

    When I try to test or generate the X++ code this method code will be built together.

    private boolean FIN_Test2()

    {

    if (ediinventtable.EDIZinc == 0)

    {

    info("Zink value is 0.00);

    return true;

    }

    else

    return false;

    }

    This is done by building together the method name with header/footer and code.

    str buildcode(str   _code, str _codeId)

    ...

    codetxt  = 'private boolean ' + A_Validate::namePrefix() + _codeId + PBA::brOpen() + PBA::brCl();

           codeTxt +=  PBA::cr() + PBA::start() + PBA::cr();

           codetxt += _code;

           codetxt += PBA::cr() + PBA::end();

    (BTW, if I add the table declaration here I will get error anyway

    codeTxt += 'InventTable inventTable' + PBA::semiColon() + PBA::cr();

    codeTxt += 'EDIInventTable  eDIInventTable' + PBA::semiColon() + PBA::cr();

    with

    Compile error: *** Error: -1, Syntax error.

    -> SemiColon is not semicolon

    or

    codeTxt += 'InventTable inventTable;' + PBA::cr();

    codeTxt += 'EDIInventTable eDIInventTable;' + PBA::cr();

    with

    Compile error: *** Error: -4, Lexical error.

    )

    The code generated will give the following error (even though I have declared it in the class declaration like class EcoResProductValidator

    class A_Validator

    {

       InventTable                 inventtable;

       EDIInventTable            ediinventtable;

    )

    with

    Compile error: *** Error: 9, Variable ediinventtable has not been declared.

    This code line will be activated.

            return checkFailed(strfmt("@SYS56146",xppCompiler.errorText()));

    If I manually try to change my method created into one with data declaration

    private boolean FIN_Test2()

    {

       InventTable                 inventtable;

       EDIInventTable              ediinventtable;

    if (ediinventtable.EDIZinc == 0)

    {

    info("Value is 0");

    return true;

    }

    else

    return false;

    }

    I will get this compile error

    The name inventtable is already used in an outer scope.

    I have this name in order to have the data record active.

    Clear?

    /Fredrik.

  • Martin Dráb Profile Picture
    234,152 Most Valuable Professional on at
    RE: Pack variables

    What do you mean by "the data declaration is missing in the method". It makes no sense to me. Please show us the code and the compilation error.

    "The variables is already declared in an outer scope" means that you're trying to add a variable with same as another variable already have in class declaration. Use a different name.

  • Community Member Profile Picture
    on at
    RE: Pack variables

    The problem is that when I try to compile the code the data declaration is missing in the method. It is however active in my classdeclaration where the method is created.

    If I add the code for creating the method and then tries to compile it from my class it will complain about the variables is already declared in an outer scope.

    What do you suggest?

  • Verified answer
    Martin Dráb Profile Picture
    234,152 Most Valuable Professional on at
    RE: Pack variables

    If you get compilation errors, the code is not compiled and you can't use it. You really have to fix compilation errors. Nothing else makes any sense.

  • Community Member Profile Picture
    on at
    RE: Pack variables

    Not really a question about the packed variables, but the same issue.

    Can I let the compiled X++ go through the compilation even though it has some errors (that the compiler thinks)?

    I have a method that I am to create/change.

    When the user enters a X++ code and the compiler checks the code the data declaration (that is declared in the class declaration is not in the method (that is if I go into the created method and have the data declaration in here I will get an error that it has already been declared in the outer scope).

    In the compilation I get xppcompilation checkfailed with Error 9 table variable (inventtable in my case) has not been declared. I can not and will not add it as previously mentioned.

    Can I let the compilation go through by setting some parameter (or let it use the current class declaration)? It will currently fail.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 50

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Featured topics

Product updates

Dynamics 365 release plans