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
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.
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);
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.
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.
Thanks a million guys.
Marek, this really help me given that I dont know much Daxing
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);
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));
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156