Hi Experts,
I have created a Enum-'NOYes' field in SalesLine.
Now I want If this field is set to Yes, the user will be unable to add, modify or remove the sales order lines.
Can anyone help how can I achieve this through X++.
Can you tell me where did you create an Yes/No enum field.
Thanks,
Girish S.
In SalesTable form, there are lot of fields in Sales line datasource. Not just in Sales order line grid but check line details. If your requirement is that no field should be editable in Sales order line then adding each field in code to make non editable is not feasible.
I would suggest to either create a dialog or custom table with a checkbox field. Check this thread
community.dynamics.com/.../can-not-make-data-source-field-editable
However, if your requirement is for only those 3-4 fields in sales order line then its feasible to add the fields in else code.
Ok Thanks Girish !!
Then the Datasource.allowedit won't work. It will disappear editing of all the datasource level fields.
In that case you need to set allow edit for each of the control in the form.
But you can use DatasourceName.allowDelete in the same code as it won't effect.
Thanks,
Girish S.
My question is suppose one time I have marked True the Boolean field and the SalesLine is non editable. Now how can I change Boolean field again to False because it is non editable now.
Please check the code I have provided, you don't need to write if else conditions. Replace NoYesField in my code with your field 'PickingInProgress_CAP'
You need to write else condition and again reset the allow edit and delete to true if the check box is No.
Thanks,
Girish S.
Hi,
Code is working now.
But How Can I set back 'No' to boolean . Because all fields are not editable now.
[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)] public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e) { FormDataSource salesLine_ds = sender; SalesLine salesLine = sender.cursor(); if ( salesline.PickingInProgress_CAP == NoYes::Yes) { SalesLine_ds.allowedit(false); SalesLine_ds.allowDelete(false); SalesLine_ds.object(fieldNum(SalesLine,PickingInProgress_CAP)).allowEdit(true); } } [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, PickingInProgress_CAP), FormDataFieldEventType::Modified)] public static void PickingInProgress_CAP_OnModified(FormDataObject sender, FormDataFieldEventArgs e) { FormDataSource salesLine_ds = sender.datasource(); SalesLine salesLine = salesLine_ds.cursor(); if ( salesline.PickingInProgress_CAP == NoYes::Yes) { SalesLine_ds.allowedit(false); SalesLine_ds.allowDelete(false); SalesLine_ds.object(fieldNum(SalesLine,PickingInProgress_CAP)).allowEdit(true); } } }
Have you debugged the code. Check if you are getting values in line# 8 and 9.
Have you debugged the code?
Thanks,
Girish S
André Arnaud de Cal...
292,111
Super User 2025 Season 1
Martin Dráb
230,934
Most Valuable Professional
nmaenpaa
101,156