Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Syslastvalue in dialogs

Posted on by Microsoft Employee
Hi If I write code like this, dialog = new Dialog("Test"); diaAddressType = dialog.addField(typeid(AddressType)); if (dialog.run()) { addressType = diaAddressType.value(); } Would it be possible to use SysLasyValue or something similar to store the value of addressType for the current user, and set that value as a default value in diaAddressType the next time the method is being run? /Jonas
  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Syslastvalue in dialogs

    Thanks. In my case the dialog was, however, opened from a Form. But I found the following article just now:

    axhelper.blogspot.com/.../storing-last-form-values.html

    that explains how to add the pack/unpack functionality to a form.

    /Jonas

  • Liviu Stoica Profile Picture
    Liviu Stoica 160 on at
    Re: Syslastvalue in dialogs

    Hi Jonas,

    I hope that  the following exemple is relevant  for you:

     


    --------------------------------------------------------------------------------------------------------------------------

    static void main(Args args)

    {

        Class1    class1;

    ;

        class1  = new Class1();

        if (class1.prompt())

            class1.run();

    }

    ---------------------------------------------------------------------------------------------------------------------
    class class1 extends RunBaseBatch
    {
        DialogRunbase                       dialog;
        // Packed variables
        TaxAddressType     addressType;
        // Dialog fields
        DialogField     dialogAddressType ;
        #define.CurrentVersion(6)
        #localmacro.CurrentList
            addressType
        #endmacro
    }
    --------------------------------------------------------------------------------------------------------------------------
    public TaxAddressType parmAddressType(TaxAddressType _addressType = addressType)
    {
        ;
        addressType = _addressType;
        return addressType;
    }
    ----------------------------------------------------------------------------------------------------------------------
    public Object dialog()
    {
    ;
        dialog = new dialogRunBase('test',this);
        xSysLastValue::getLast(this);
        dialogAddressType  = dialog.addField(typeid(taxAddressType));
        dialogAddressType.value(this.parmAddressType());
        return dialog;
    }
    -------------------------------------------------------------------------------------------------
    public boolean getFromDialog()
    {
        boolean                 ret;
        ;
        ret                     = super();
        addressType   = dialogAddressType.value();
        return ret;
    }
    ----------------------------------------------------------------------------------------------------
    public container pack()
    {
        ;
        return [#CurrentVersion, #CurrentList];
    }
    ------------------------------------------------------------------------------------------------------
    public boolean unpack(container packedClass)
    {
        Integer     version         = RunBase::getVersion(packedClass);
        ;
        switch (version)
        {
            case #CurrentVersion :
                [version, #CurrentList] = packedClass;
                break;
            default :
                return false;
        }
        return true;
    }
    ---------------------------------------------------------------------------------------------------------------
    // Here goes a description of the class
    static ClassDescription description()
    {
        return "class1";
    }
    =================================================================
    public void run()
    {
        #OCCRetryCount
        try
        {
            ttsbegin;
            info(strfmt('%1',addressType));
            xSysLastValue::saveLast(this);
            ttscommit;
        }
        catch (Exception::Deadlock)
        {
            retry;
        }
        catch (Exception::UpdateConflict)
        {
            if (appl.ttsLevel() == 0)
            {
                if (xSession::currentRetryCount() >= #RetryNum)
                {
                    throw Exception::UpdateConflictNotRecovered;
                }
                else
                {
                    retry;
                }
            }
            else
            {
                throw Exception::UpdateConflict;
            }
        }
    }
    ================================================================
    Best regards,
    Liviu Stoica
    Dynamics AX Developer

     

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans