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 224

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

  • Willem van Duren Profile Picture
    224 on at
    RE: SalesTable form , Set Allowedit false for date field

    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.

  • Willem van Duren Profile Picture
    224 on at
    RE: SalesTable form , Set Allowedit false for date field

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

  • Verified answer
    udaY-ch Profile Picture
    4,624 on at
    RE: SalesTable form , Set Allowedit false for date field

    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

  • Verified answer
    WillWU Profile Picture
    22,352 on at
    RE: SalesTable form , Set Allowedit false for date field

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

  • Willem van Duren Profile Picture
    224 on at
    RE: SalesTable form , Set Allowedit false for date field

    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. 

  • udaY-ch Profile Picture
    4,624 on at
    RE: SalesTable form , Set Allowedit false for date field

    hi

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

    axnotesblog.wordpress.com/.../

    Uday

  • Willem van Duren Profile Picture
    224 on at
    RE: SalesTable form , Set Allowedit false for date field

    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.

  • André Arnaud de Calavon Profile Picture
    293,129 Super User 2025 Season 1 on at
    RE: SalesTable form , Set Allowedit false for date field

    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.

  • udaY-ch Profile Picture
    4,624 on at
    RE: SalesTable form , Set Allowedit false for date field

    Hi,

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

    Uday

  • Suggested answer
    Mea_ Profile Picture
    60,278 on at
    RE: SalesTable form , Set Allowedit false for date field

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,129 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans