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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

SalesTable form , Set Allowedit false for date field

(0) ShareShare
ReportReport
Posted on by 230

Hi everyone,

I am trying to conditionally block a field based on the legal entity. I made an extension of the salestable form, and datasource class Salesline, method active.

It builds well, but does not work. I guess I am doing something wrong. I hope that somebody is able to help me out:

ExtensionOf(formStr(SalesTable))]
public final class ELCWDSalesTableUS0008_Extension
{
    [DataSource]
    class SalesLine
    {
        int active(boolean _mcrFormPartUpdateOnly = false)
        {
            int     ret;
            next active(_mcrFormPartUpdateOnly);
            
            if(curExt()=="ENTNL")
            {
                SalesLine_ds.object(fieldNum(SalesLine, ShippingDateConfirmed)).allowedit(false);
            }
            
            return ret;
        }
    }
}

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Put a breakpoint there and see what happens. Code looks ok but maybe company name is wrong or there is another place in the code that makes it editable again after active.

  • udaY-ch Profile Picture
    5,133 on at

    Hi,

    Does the company used is correct? The maximum size of the dataAreaId is 4 char.

    Uday

  • André Arnaud de Calavon Profile Picture
    301,053 Super User 2025 Season 2 on at

    Hi Willem,

    My first guess is the company condition. You used a hard-coded company name with 5 characters where the default is only allowing 4 characters as company ID.

  • Willem van Duren Profile Picture
    230 on at

    Good morning! Thank you for your suggestions.

    To make sure that the Legal Entity was not the problem, I removed this code and added a breakpoint. This has the same result: the field remains editable.

    Also the breakpoint is not hit. Maybe the active method is not the right one in this form? 

    Visual studio mentions during debugging that the breakpoint will not be hit because symbols are not loaded. I double checked my settings, but the " Load symbols only for items in the solution" is unchecked as it is supposed to be.

  • udaY-ch Profile Picture
    5,133 on at

    hi

    I can see that you want to create extension using COC.

    axnotesblog.wordpress.com/.../

    Uday

  • Willem van Duren Profile Picture
    230 on at

    Hi Uday!

    Yes I used chain of command. Should I use event handler instead?

    I read the article in your link. I tried to change my code to that example:

    [ExtensionOf(FormDatasourceStr(Salestable,Salesline))]
     final class ELCWDSalesTableUS0008_Extension
    {
                int active(boolean _mcrFormPartUpdateOnly = false)
            {
                int     ret;
                next active(_mcrFormPartUpdateOnly);
                SalesLine_ds.object(fieldNum(SalesLine, ShippingDateConfirmed)).allowedit(false);
                          
                return ret;
            }
    

    I get multiple errors:

    Error The augmented class 'FormDataSource' provides a method by this name, but this method cannot be used as a chain of command method since the parameter profile does not match the original method. 

  • Verified answer
    WillWU Profile Picture
    22,361 on at

    Hi Willem,

    You could use FormDataSourceEventHandler.

     [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]
        public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
    
            FormDataSource salesline_ds = sender.formRun().dataSource("SalesLine");
            //if condition
            SalesLine_ds.object(fieldNum(SalesLine, ShippingDateConfirmed)).allowedit(false);
        }

  • Verified answer
    udaY-ch Profile Picture
    5,133 on at

    Hi

    [ExtensionOf(FormDatasourceStr(SalesTable,SalesLine))]

    final class SalesTable_extension

    {    

       int active()

       {

           int     ret;

           FormDataSource salesLineds;

           salesLineds = this.formrun().datasource(FormDatasourceStr(SalesTable,SalesLine));

           ret = next active();

           salesLineds.object(fieldNum(SalesLine, ShippingDateConfirmed)).allowedit(false);

           return ret;

       }

    }

    Uday

  • Willem van Duren Profile Picture
    230 on at

    Hi Will! Thanks for your help.

    I changed to Event handler, but the field remains editable:

    public static class ELCWDSalesTableUS0008_Extension
    {
    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]
        public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
    
            FormDataSource salesline_ds = sender.formRun().dataSource("SalesLine");
            //if condition
            SalesLine_ds.object(fieldNum(SalesLine, ShippingDateConfirmed)).allowedit(false);
        }
    
    }

  • Willem van Duren Profile Picture
    230 on at

    Ok. I Tried it on another field. This blocks well. So it seems ievgen is right: after the allowedit(false) it seems it is being enabled again. I will check and reply back.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans