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, ...
Suggested Answer

Can not make data source field editable!!

(0) ShareShare
ReportReport
Posted on by

Hi;

I need to add a string field to "custinvoiceJournal" form and make this field (only) editable. This is just an informative field.

As you know, this form's dataSource "custInvoiceJour" property "AllowEdit" is set by default as False.

I made 2 extensions: one for the table, the other is for the form and added my new field.

Then I used the "OnInitialized" form event Handler to make this field editable. However, this didn't work.

The field still disabled. 

[FormEventHandler(formStr(CustInvoiceJournal), FormEventType::Initialized)]
public static void CustInvoiceJournal_OnInitialized(xFormRun sender, FormEventArgs e)
{
    FormRun fr = sender;
    FormDataSource fds = sender.dataSource(formDataSourceStr(CustInvoiceJournal,CustInvoiceJour));
    fds.object(fieldNum(CustInvoiceJour,MyField)).allowEdit(true);
}

I also tried using COC on the init() form method, and still not working..

Am I missing something here?

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    You can't make a field editable if the whole data source is read-only.

    Consider using a drop dialog to change the field. I would also prefer putting the field to a separate table.

  • Community Member Profile Picture
    on at

    Hi Martin;

    This is a bit strange. If you look at the original form code, in the init method, you may see that in some situations the whole datasource may be opened for editing.

    for example :

    after the super() in init() you have a call to    element.initDesign_FR();
    
    void initDesign_FR()
    
       {
    
           if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoFR]))
    
           {
    
               custInvoiceJour_DS.allowEdit(true);
    
               allowEditFieldsOnFormDS_W(custInvoiceJour_DS, false);
    
           }
    
       }
    
    Here, data source editing is enabled. So I tried to do the same in the event handler, but also this didn't work:
    
    [FormEventHandler(formStr(CustInvoiceJournal), FormEventType::Initialized)]
    
    public static void CustInvoiceJournal_OnInitialized(xFormRun sender, FormEventArgs e)
    
    {
    
       FormRun fr = sender;
    
       FormDataSource fds = sender.dataSource(formDataSourceStr(CustInvoiceJournal,CustInvoiceJour));
    
       fds.allowEdit(true);
    
    }

    I wanted to open the whole dataSource for editing, then disable all fields except my field..

  • Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    If you're willing to enable the whole data source, then it's also an option.

    Try debugging the form; maybe allowEdit is set back to false in some code executed later.

    By the way, your code will be much simpler if you use CoC:

    public void init()
    {
    	next init();
    	custInvoiceJour_ds.allowEdit(true);	
    }

    instead of

    public static void CustInvoiceJournal_OnInitialized(xFormRun sender, FormEventArgs e)
    {
       FormRun fr = sender;
       FormDataSource fds = sender.dataSource(formDataSourceStr(CustInvoiceJournal,CustInvoiceJour));
       fds.allowEdit(true);
    }

    Also, please use Insert > Insert code (in the rich formatting view) to paste source code (as I did).

  • Community Member Profile Picture
    on at

    Hi Martin;

    I tried also COC, same result.

    I couldn't find any other code that might blocks editing after my code runs.

  • Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    Yes, CoC will give you the same result. That was my point - that you can get the same result with less code that is easier to write and read. I didn't meant that it'd behave differently.

  • Suggested answer
    Vishal Dhavgaye Profile Picture
    405 on at

    Is there specific reason why you want to edit your field on sales invoice? Once sales invoice is posted we shouldn't be making any changes to it.

    You can have this field on sales order, have it editable on sales order and populate it on custInvoiceJour on invoice posting.

  • Community Member Profile Picture
    on at

    The customer need this field for reporting and query in other forms and report, and he wants to update this field after the invoice is created.

    Again,I can't find the actual technical place where blocking data source is done after I opened it it the event handler..and as I mentioned before, in some cases this data source can be editable (Vanilla code).

    Could this be the "Table group" - (transaction tables)?

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

    Hi Ebrahim,

    Have you considered creating a new table with a relation to the custInvoiceJour table? Then you are able to control the field value without additional coding as it is in a separate table without the default where you are not allowed to make any changes to posted details.

  • Community Member Profile Picture
    on at

    Yes, probably, this what i think to do, although I think there should be posibility to modify this data source editability regardless what data source is it.

  • NoobDaxCoder Profile Picture
    6 on at

    Hi Andre/Martin,

    I am currently working on upgrade + implementation project. In that i ran into similar problem like original poster. 

    The DS tmpReqExplosionOnhand in form ReqTransExplosion is allow edit false in sys layer/application suite In AX2012, It was overlayered to allow edit true.  In D365 it is not possible to modify the DS properties. So I have to tried make it editable through code in Form init, Form DS init, Form DS active method. However, this won't make the form or the control editable.

    I have to create duplicate table and add it in the form. Is that solution for this problem?

    Thanks,

    V

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 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans