Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

getting value from dialog field

(0) ShareShare
ReportReport
Posted on by 768

Hello,

I'm trying to get value from dialogfield in the method dialog() in the class inherited from RunBaseBacth class I'm writing the following:

protected Object dialog()
{
    DialogRunbase       dialog = new DialogRunbase('Анализ количества технически обоснованных форм', this);
    DialogGroup         dialogGroup;

    dialogGroup         = dialog.addGroup('Parameters');
    dialogGroup.caption('Параметры');

    dlgReportSelectMethod   = dialog.addfieldvalue(enumstr(TechnReasonableReportSelectMethod_ICL1),reportSelectMethod);
    dlgFromDate             = dialog.addFieldValue(extendedTypeStr(FromDate),fromDate);
    dlgToDate               = dialog.addFieldValue(extendedTypeStr(ToDate),toDate);
    dlgItemId               = dialog.addFieldValue(extendedTypeStr(ItemIdProduction),itemIdProduction);
    dlgInventSiteId         = dialog.addFieldValue(extendedTypeStr(InventSiteId),inventSiteId);

    dlgItemId.registerOverrideMethod(methodStr(FormStringControl, lookup)
                                     ,methodStr(ExportAnalisTechnJustifiedNorms_ICL,customLookup)
                                     ,this);

    return dialog;

}


Depending on the value which user has chosen in the field dlgReportSelectMethod I would like other values to become enabked or disabled. I know this is done through dlgToDate.enabled() method. But I don't understand how to retrieve the values of the field dlgReportSelectMethod. I tried dlgReportSelectMethod.value() but with no success.

Could please someone assist kindly?

Thank you.

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: getting value from dialog field

    You can use the debugger to verify actual value and to see what exactly is going on in your code.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: getting value from dialog field

    I agree it works. but dlgToDate.enabled(reportSelectMethod) doesn't. Can't understand why. reportSelectMethod - contains value 0. so it must be like dlgToDate.enabled(false), right? Anyway I have rewritten in other way - dlgitemId.enabled(dlgReportSelectMethod.value()) and it works. Thanks. And now the main question for me is why when I change value in the dialog dlgReportSelectMethod field doesn't show new value in the dialog form. It stays the same all the time. It happened after I've overridden modified() method of control of the field dlgReportSelectMethod.

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: getting value from dialog field

    Here is a proof of concept that you can run in a job and see that it works.

    date toDate = today();
    boolean reportSelectMethod = true;
    Dialog dialog = new Dialog();
    
    DialogField dlgToDate = dialog.addFieldValue(extendedTypeStr(ToDate), toDate);
    dlgToDate.enabled(!reportSelectMethod);
    
    dialog.run();
  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: getting value from dialog field

    OK. I've written the following:

    protected Object dialog()
    {
        DialogRunbase       dialog = new DialogRunbase('Анализ количества технически обоснованных форм', this);
        DialogGroup         dialogGroup;
    
        dialogGroup         = dialog.addGroup('Parameters');
        dialogGroup.caption('Параметры');
    
        dlgReportSelectMethod   = dialog.addfieldvalue(enumstr(TechnReasonableReportSelectMethod_ICL1),reportSelectMethod);
        dlgFromDate             = dialog.addFieldValue(extendedTypeStr(FromDate),fromDate);
        dlgToDate               = dialog.addFieldValue(extendedTypeStr(ToDate),toDate);
        dlgItemId               = dialog.addFieldValue(extendedTypeStr(ItemIdProduction),itemIdProduction);
        dlgInventSiteId         = dialog.addFieldValue(extendedTypeStr(InventSiteId),inventSiteId);
        
        dlgToDate.enabled(!reportSelectMethod);
        dlgFromDate.enabled(!reportSelectMethod);
        dlgitemId.enabled(reportSelectMethod);
        dlgitemId.value('');
        dlgFromDate.value(mkDate(1,1,year(systemDateGet())));
        dlgToDate.value(mkDate(31,12,year(systemDateGet())));
        
        dlgItemId.registerOverrideMethod(methodStr(FormStringControl, lookup)
                                         ,methodStr(ExportAnalisTechnJustifiedNorms_ICL,customLookup)
                                         ,this);
        dlgReportSelectMethod.registerOverrideMethod(methodStr(FormCheckBoxControl, modified)
                                         ,methodStr(ExportAnalisTechnJustifiedNorms_ICL, reportMethodModified)
                                         ,this);
        
        return dialog;
    
    }

    dlgitemId.enabled(reportSelectMethod); - doesn't work for some reason. reportSelectMethod - it contains 0 or 1 depending on the enum values, correct? !reportSelectMethod works and reportSelectMethod doesn't. Can't get why to be honest. What's the difference?  Also when I change dlgreportSelectMethod  its values still don't refresh in the dialog... I suppose I miss something crucial.

    Thank you.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: getting value from dialog field

    Yes, you can do it in dialog(). That's exactly where you're building the dialog and setting initial values, therefore you do have initial field values.

    For example, you have code like this:

    dialog.addfieldvalue(enumstr(TechnReasonableReportSelectMethod_ICL1),reportSelectMethod);

    It's saying that the value of of the dialog field should be set to what's in reportSelectMethod variable. Therefore you can simply use this variable in a condition and do whatever you like. For example:

    dlgToDate.enabled(!reportSelectMethod);
  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: getting value from dialog field

    Thank you. Could you please tell me where to look exactly? which method? Dialog is initialized in dialog() method as I get it but there I can't use the same logic because the field values are inaccessible there. I was tasked to do via OXML technology and class XMLExcelReport_RU which in tern inherits from RunBaseBatch which inherits from RunBase. Much appreciated your answers. Also as wrote above can't get why value of the field dlgReportSelectMethod doesn't change even when I choose other value from drop-down list.

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: getting value from dialog field

    Can you please elaborate why you believe that you can't use SysOperation framework?

    If you've implemented your logic to be executed only when user modify the field, you can't expect it to be magically applied in other cases too. If you want the same logic applied when the dialog is being initialized, you mist call your logic there as well.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: getting value from dialog field

    Thank you for your answer. I was tasked to do via OXML technology so can't use SysOperation classes.

    I have added additional method to my class:

    private void reportMethodModified(FormCheckBoxControl _checkBoxControl)
    {
        if(dlgReportSelectMethod.value())
        {
            dlgToDate.enabled(false);
            dlgFromDate.enabled(false);
            dlgItemId.enabled(true);
    
            dlgFromDate.value('');
            dlgToDate.value('');
        }
        
        else
        {
            dlgToDate.enabled(true);
            dlgFromDate.enabled(true);
            dlgitemId.enabled(false);
            dlgitemId.value('');
            dlgFromDate.value(mkDate(1,1,year(systemDateGet())));
            dlgToDate.value(mkDate(31,12,year(systemDateGet())));
        }
    }


    Then my dialog() method looks like that:

    protected Object dialog()
    {
        DialogRunbase       dialog = new DialogRunbase('Анализ количества технически обоснованных форм', this);
        DialogGroup         dialogGroup;
    
        dialogGroup         = dialog.addGroup('Parameters');
        dialogGroup.caption('Параметры');
    
        dlgReportSelectMethod   = dialog.addfieldvalue(enumstr(TechnReasonableReportSelectMethod_ICL1),reportSelectMethod);
        dlgFromDate             = dialog.addFieldValue(extendedTypeStr(FromDate),fromDate);
        dlgToDate               = dialog.addFieldValue(extendedTypeStr(ToDate),toDate);
        dlgItemId               = dialog.addFieldValue(extendedTypeStr(ItemIdProduction),itemIdProduction);
        dlgInventSiteId         = dialog.addFieldValue(extendedTypeStr(InventSiteId),inventSiteId);
        
        dlgItemId.registerOverrideMethod(methodStr(FormStringControl, lookup)
                                         ,methodStr(ExportAnalisTechnJustifiedNorms_ICL,customLookup)
                                         ,this);
        dlgReportSelectMethod.registerOverrideMethod(methodStr(FormCheckBoxControl, modified)
                                         ,methodStr(ExportAnalisTechnJustifiedNorms_ICL, reportMethodModified)
                                         ,this);
        
        return dialog;
    
    }


    I have overridden modified() method acting on your advice. It works but not as I expected:

    1) Firstly, when I open the dialog there is a value already in dlgReportSelectMethod. For you to understand the values in Russian (sorry)

    По производственной программе = enum value 0

    По изделию = enum value 1

    So when I open the dialog there is a default value dlgReportSelectMethod = По производственной программе = enum value 0  but dialog doesn't update other field (dlgFromDate, dlgToDate, dlgItemId) values until I manually modify dlgReportSelectMethod and that's expected behavior. Is there any workaround for this? Maybe at least make a value for dlgReportSelectMethod to be empty somehow until user chooses one and modified() method will trigger.

    2) When I choose any value in field dlgReportSelectMethod overridden method modified() works correct but visible value in dlgReportSelectMethod field stays the same even when I change it. So even if I choose По производственной программе = enum value 0 or По изделию = enum value 1 the visible value stays the same "По производственной программе". I have chosen two different values in dlgReportSelectMethod field. Overridden method modified() worked fine but the visible value in the form stays the same По производственной программе. Is there any way to refresh it?

    0434.111.JPG

    Then I choose По изделию = enum value 1 but dlgReportSelectMethod field visible value stays the same (however overridden method modified() method worked fine)

    1385.113.JPG

    How to fix this?

    When I do without overridden method modified() (commented it) it changes correctly:

    1385.113.JPG

    0434.111.JPG

    Thank you.

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: getting value from dialog field

    You can't access values selected by users, because dialog() is called when defining how the dialog will look like. It will be executed later.

    When a user set values and confirm the dialog, you can read values in getFromDialog().

    But in your case, it sounds like the right course of action would be register a method to be executed when user modifies dlgReportSelectMethod value. (Search for 'registerOverrideMethod'.)

    By the way, don't you want to use the newer framework, SysOperation, instead? It can generate UI for you and you'll simply override the method in the UI builder class.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans