Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Allow edit to only one field in Datasource

Posted on by 485

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

  • Suggested answer
    ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Allow edit to only one field in Datasource

    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.

  • Ashrafhk Profile Picture
    Ashrafhk 90 on at
    RE: Allow edit to only one field in Datasource

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Allow edit to only one field in Datasource

    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.

  • Lionel07 Profile Picture
    Lionel07 485 on at
    RE: Allow edit to only one field in Datasource

    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.

  • Lionel07 Profile Picture
    Lionel07 485 on at
    RE: Allow edit to only one field in Datasource

    Thanks a million guys.

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Allow edit to only one field in Datasource

    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);
    
    
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Allow edit to only one field in Datasource

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




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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans