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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 1,274

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

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    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;
    }


  • dark_knight Profile Picture
    1,274 on at

    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
    101,172 Moderator on at

    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
    1,274 on at

    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.

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    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
    1,274 on at

    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?

  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    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
    1,274 on at

    Thanks Nikolaos:)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans