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 :
Microsoft Dynamics AX (Archived)

Allow edit to only one field in Datasource

(0) ShareShare
ReportReport
Posted on by 495

Hello Experts,

I would appreciate if someone could help me figure out how to make only one field editable in a datasource

Take for example: datasource CustInvoiceJour, in this datasource I have the field printedorginal which I would like to make editable (ONLY). I have set allow edit to yes and also AllowAdd to "yes" but it still not allowing me to edit it. What I have notice though is if I set the datasource itself to editable then it will become editable but i dont want that because all other fields would be editable.

Your kind help is greatly appreciated.

*This post is locked for comments

I have the same question (1)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Lionel,

    one approach can be:

    1) set datasource to AllowEdit = true   

    2) write a method to iterate over all fields on the datasource and set them to AllowEdit = false, except the one field which we want to leave editable   

    3) call this method after super() in datasource's  init() method

    The method can be slightly modified version of standard method  Global::allowEditFieldsOnFormDS_W(...) like this:

    client static public void myAllowEditFieldsOnFormDS_W(FormDataSource _dataSource, boolean _allowEdit, FieldId _excludeField)
    {
        DictTable       dictTable = new DictTable(_dataSource.table());
        DictField       dictField;
        FormDataObject  dataObject;
        int             cx, idx;
    
        for (cx = 1; cx <= dictTable.fieldCnt(); cx ++)
        {                
            dictField = dictTable.fieldObject(dictTable.fieldCnt2Id(cx));
            
            if (dictField.id() != _excludeField && !dictField.isSystem())
            {
                for (idx = 1; idx <= dictField.arraySize(); idx++)
                {
                    dataObject = _dataSource.object(fieldId2Ext(dictField.id(), idx));
                    if (dataObject)
                    {
                        dataObject.allowEdit(_allowEdit);
                    }
                }
            }
        }
    }


    And the call in init() method of the datasource would be:

    MyClass::myAllowEditFieldsOnFormDS_W(CustInvoiceJour_ds, false, fieldNum(CustInvoiceJour, PrintedOrginal));




  • Verified answer
    Community Member Profile Picture
    on at

    Or even easier solution without custom method:

    1) set datasource to AllowEdit = true

    2) in datasource's  init() method after super() simply call:

    allowEditFieldsOnFormDS_W(CustInvoiceJour_ds, false);
    CustInvoiceJour_ds.object(fieldNum(CustInvoiceJour, PrintedOrginal)).allowEdit(true);
    
    
  • Lionel07 Profile Picture
    495 on at

    Thanks a million guys.

    Marek, this really help me given that I dont know much Daxing

  • Lionel07 Profile Picture
    495 on at

    One more question guys, for my field printedOriginals i want only 3 users to be able to edit the field. is this something i AX 2012 can allow? if you is there how can i do please..... I would prefer a non coding solution is possible please.

    thanks for your help.

  • Community Member Profile Picture
    on at

    Since there is a customization on the form method already, I'd personally go for a simple solution:


    1) Create a user group in AX2012 (System administration > Common > Users > User groups)
    2) Assign users to above mentioned group (in example below named 'InvEditOrg')
    3) In code call allowEdit only if current user is set as a member of the group:

    allowEditFieldsOnFormDS_W(CustInvoiceJour_ds, false);
    if (UserInfoHelp::userInUserGroup(curUserId(), 'InvEditOrg'))
    {
        CustInvoiceJour_ds.object(fieldNum(CustInvoiceJour, PrintedOriginals)).allowEdit(true);
    }
    


    This allows adding/removing users by setup without further coding.

    If you do not like the hardcoded group name, it can be added as a field to any parameters table (maybe CustParameters) and using it from there.

  • Ashrafhk Profile Picture
    90 on at

    It's not working for multiple fields

    allowEditFieldsOnFormDS_W(smmBusRelTable_ds,false);

           smmBusRelTable_ds.object(fieldNum(smmBusRelTable, CustGroup)).allowEdit(true);

           allowEditFieldsOnFormDS_W(SalesQuotationTable_ds,false);

           CustTableQuotationTable_ds.object(fieldNum(CustTable, InvoiceAccount)).allowEdit(true);

           SalesQuotationTable_ds.object(fieldNum(SalesQuotationTable, SalesIdRef)).allowEdit(true);

           allowEditFieldsOnFormDS_W(LogisticsPostalAddressHeader_ds,false);

           LogisticsPostalAddressHeader_ds.object(fieldNum(LogisticsPostalAddress, Address)).allowEdit(true);

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    It is Works. It's not a case of how many different ds or fields you're writing this code for.

    Probably allowEdit is set to false either in the properties of the form ds or in the code.

    Before using the code make sure you have allowEdit=true value (maybe can added table_ds.allwEdit(true)). And Make sure the value don't get overided after your code either. Likewise, there should not be any code that set allowEdit after you for the fields.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans