Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

make a field inactive based on the values of the table missing in forms datasources

Posted on by 768

Hello,

Could you please point me to the right direction?

I have added a field to the form "ProdJournalTransRoute"

7652.111.JPG

I need to make this field inactive or active  based on the field value "ToDate" from the view called "ProdRouteSchedulingView"

5518.112.JPG

Values to this view are entered on the form called "ProdRoute":

0385.113.JPG

I have 2 questions:

1) Why I can't enter "ToDate" values in the form "ProdRoute"? I have highlighted it in the screenshot above. This leades the needed view "ProdRouteSchedulingView" doesn't have "ToDate" values as well.

2) The second question. To make my new field active or inactive based on the values of the "ToDate" from view "ProdRouteSchedulingView" I write the following code in the 'Active" method in the  datasource ProdJournalRoute of the form "ProdJournalTransRoute"

int active()
{
    int ret;
    ProdRouteSchedulingView  prodRouteSchedulingView;

    ret = super();

    journalFormTrans.datasourceActivePost();
    if (prodJournalRoute.isProjMethodConsumed())
    {
        skipWrite = true;
        prodJournalRouteProjHour_ds.executeQuery();
        prodJournalRouteProjQuantity_ds.executeQuery();
        skipWrite = false;
    }


    element.enableFieldsActive();
    dimensionDefaultingController.activated();

    select firstOnly * from prodRouteSchedulingView
        join ProdJournalRoute
            where ProdJournalRoute.ProdId == prodRouteSchedulingView.ProdId &&
                  ProdJournalRoute.OprId == prodRouteSchedulingView.OprId &&
                  ProdJournalRoute.OprNum == prodRouteSchedulingView.OprNum;

    if (ProdJournalRoute.TransDate >= prodRouteSchedulingView.ToDate)
    {
        ProdJournalRoute_ds.object(fieldNum(ProdJournalRoute,BreakdownReasonId_ICL)).allowEdit(false);
    }

    return ret;
}


The needed record is found and there is "ToDate" value empty but the client is crashing on the "return ret" string. Tell me please what I'm doing wrong? Maybe that's because "ToDate" value is empty? But I can't enter it as I described above.

Thank you.

*This post is locked for comments

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    Thanks Nikolaos:)

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    Values appear if they are populated in code. AllowEdit and AllowEditOnCreate properties only control behavior in UI (and Excel and AIF).

    You can use cross references tool (right click any object in AOT - Add-ins - Cross References - Used by) to figure out how they are used in the system. This is a very important tool for developers. Please also set a batch job to update your cross reference data regularly.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    yes you are right. AllowEditONcreate and AllowEdit of the field "ToDate" of the table "ProdRoute" is set to "NO" but in that case how values appear there?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    Did you look how that date field is set up. Maybe it's using a display method? Maybe it's a field where AllowEdit is No.

    I don't have a system at hand right now so I can't check. But please check properties Data source, Data field and/or Data method of the ToDate form control. I'm sure you can figure it out.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    Thanks a lot. Brilliant! And still the same question as above. Maybe you know anything:

    1) Why I can't enter "ToDate" values in the form "ProdRoute"? I have highlighted it in the screenshot above. This leades the needed view "ProdRouteSchedulingView" doesn't have "ToDate" values as well.

    I need to change this value to test the code more thoroughly.

    Thank you.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    I mean method "enableFieldsActive" on the form, like I wrote.

    As you can see, it's called from the active method. Instead of placing your code in active method, you could put it in the enableFieldsActive method.

    Then all future developers could easily find all code that impacts enabling/disabling fields in one central place.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    Thank you very much. Seem like it works. Thank you for your remarks. Really appreciated.

    Don't you know by the way how can I add values to "ToDate" field to the "prodRouteSchedulingView"? It's not editable.

    Also about:

    [quote user=""Nikolaos"]Third thing, I'd say it's better if you put your code in the enableFieldsActive method which is clearly intended for handling enabling/disabling of fields.[/quote]

    What method do you mean?

    Many thanks.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: make a field inactive based on the values of the table missing in forms datasources

    In the code of your active method, why are you joining to ProdJournalRoute? It seems unnecessary, and maybe that causes the crashing. Basically in your data source's active method you are selecting another record in the same data source buffer.

    Another thing, you have no handling for setting allowEdit back to true on records where it should be allowed.

    Third thing, I'd say it's better if you put your code in the enableFieldsActive method which is clearly intended for handling enabling/disabling of fields.

    But putting my last point aside, your active method should look something like this:

    int active()
    {
        int ret;
        ProdRouteSchedulingView  prodRouteSchedulingView;
    
        ret = super();
    
        journalFormTrans.datasourceActivePost();
        if (prodJournalRoute.isProjMethodConsumed())
        {
            skipWrite = true;
            prodJournalRouteProjHour_ds.executeQuery();
            prodJournalRouteProjQuantity_ds.executeQuery();
            skipWrite = false;
        }
    
    
        element.enableFieldsActive();
        dimensionDefaultingController.activated();
    
        select firstOnly RecId from prodRouteSchedulingView
    	where projRouteSchedulingView.ProdId == prodJournalRoute.ProdId
    		&& prodRouteSchedulingView.OprId == prodJournalRoute.OprId
    		&& prodRouteSchedulingView.OprNum == prodJournalRoute.OprNum
    		&& prodRouteSchedulingView.ToDate < prodJournalRoute.TransDate;
    
        ProdJournalRoute_ds.object(fieldNum(ProdJournalRoute,BreakdownReasonId_ICL)).allowEdit(prodRouteSchedulingView.RecId ? true : false);
    
        return ret;
    }


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans