web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

I have the same question (0)
  • Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    Can you explain the problem in your form?

    Also, what are you trying to achieve with your class? I could tell you how to fix the packing, but I suspect you don't need it at all.

  • Community Member Profile Picture
    on at

    Ok, when I select validate button from Released product details I will end up in checkValidationRules in class EcoResProductValidator. In here I want to add a couple of rules on my own (bases on a new db-table with xppcompiled code). The problem is when I go to my new created class and methods I don't have access to the ItemId. This causes that I don't know which product I am coming from.

  • Verified answer
    Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    So you're calling your class from EcoResProductValidator, right?

    You have to get a reference to InventTable. Either pass InventTable to your class, or pass a reference to EcoResProductValidator ("this") and then  call parmInventTable().

    You can pass the reference either to a constructor or through a method.

  • Verified answer
    Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    EcoResProductValidator::construct() can serve as an example.

  • Community Member Profile Picture
    on at

    Hi,

    I don't get it to work.

    In class EcoResProductValidator I have added this piece of code.

    protected boolean checkValidationRules()

    ...

       // A_ProductChange Start

       productValidator = A_Validator::construct(inventTable);

       result = A_Validator::checkValidationRules() && result;

       // A_ProductChange End

    ...

    This is my calling construct.

    public static A_Validator construct(InventTable _inventTable)

    {

       A_Validator productValidator = new A_Validator();

       productValidator.parmInventTable(_inventTable);

       return productValidator;

    }

    public InventTable parmInventTable(InventTable _inventTable = inventTable)

    {

       inventTable = _inventTable;

       return inventTable;

    }

    Now I still have the info in inventTable, but when I enter my class method

    it is gone.

    public static boolean checkValidationRules()

    ...

    Where do I go wrong?

    Suppose I have more tables than InventTable to pass, how can I do this?

    Regards,

    /Fredrik.

  • 5400 Profile Picture
    7,162 on at

    Hi fedric,

    I have small suggestion why you are not initializing your class under

    \Classes\EcoResProductValidatonServiceProxy\validateProductsFromDataSource

    as per standard and pass the value through parm as bindata. Hope your validation method gets call in same time.I don't know what is your scenario in details .

    If you want to intialize by inventTable  your class you can do below place also as per standard.

    \Classes\EcoResProductValidatonService\validateProducts

    Thanks

    Bhaskar

  • Suggested answer
    Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    Your checkValidationRules() is static, therefore it can't access the instance variable. That the method is static seems to be a bug (and you're obviously using some other, uninitialized variable there, which is another thing you have to fix).

    Alternatively, you could keep the method static but you would have to pass InventTable as a parameter.

  • Community Member Profile Picture
    on at

    You mean a call to my class in here? Do I set up datacontracts? Don't know how this works. Do I use the wrong class? I have a db-table with xpp-compiled code I want to run for each field in the db-table (db-name and field, fi. InventTable ItemId (x++ code: length must be 10 characters)). It has generated a method in a separate class and I want to run through these rules and display the outcome in an infolog like above if the check fails on InventTable.ItemId field some text like Field needs to be 10 characters will appear.

  • Community Member Profile Picture
    on at

    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.

  • Verified answer
    Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans