Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / SalesTable form , Set ...
Finance forum
Answered

SalesTable form , Set Allowedit false for date field

Posted on by 220

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
    Willem van Duren 220 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
    Willem van Duren 220 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
    udaY-ch 4,616 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
    WillWU 22,344 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
    Willem van Duren 220 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
    udaY-ch 4,616 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
    Willem van Duren 220 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
    André Arnaud de Cal... 287,914 Super User 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
    udaY-ch 4,616 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
    Mea_ 60,274 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans