Notifications
Announcements
No record found.
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++.
Hi Harish,
You can set the condition on the active method of the SalesLine datasource.
Set the datasource allow edit property to No.
Thanks,
Girish S.
Hi Girish,
How to write the logic . I have written the code like this -
[ExtensionOf(formControlStr(SalesTable, SalesLine_PickingInProgress_CAP))] internal final class SalesLine_PickingInProgress_CAP_Extension { public void OnModified() { FormControl formButtonControl = any2Object(this) as FormControl; FormDataSource formDatasource = formButtonControl.formRun().dataSource(tableStr(SalesTable)); SalesTable salesTable = formDatasource.cursor(); SalesLine salesLine; while select SalesLine where salesLine.SalesId == SalesTable.SalesId { if (salesLine.PickingInProgress_CAP == NoYes::Yes) { //formDatasource.object(FormTabPageControl, LineViewLines).allowEdit(false); formDatasource.object(fieldNum(SalesLine, ItemId)).allowEdit(false); formDatasource.object(fieldNum(SalesLine, SalesQty)).allowEdit(false); formDatasource.object(fieldNum(SalesLine, QtyOrdered)).allowEdit(false); formDatasource.object(fieldNum(SalesLine, SalesPrice)).allowEdit(false); } } } }
You need to add code in active method of SalesLine datasource. And Instead of checking all sales order lines, active method should check the NoYes field value and make the fields editable or non editable. Also, you mentione din the question that user should not be allowed to create, delete or edit the record, what if this field is Yes in one sales order line but No in another, what is the expectation in that case.
Hi Mohit,
My requirement is -
If this field is set to Yes, the user will be unable to add, modify or remove the sales order lines. Users will continue to be able to edit the sales order header and perform other functions such as generating picking lists, warehouse work, etc. But will be unable to make changes to values on the sales order line .
For unable to add, modify or remove requirement, is it based on YesNo value found in any of sales order line or all sales order lines.
Instead of allowEdit on field level, you should use SalesLine datasource allowCreate, allowEdit and allowDelete properties.
Yes setting datasource.allowedit(false) and allow Delete(flase) at active method will meet your scenario you are expecting.
It should be YesNo value found on particular Sales line.
Can you suggest a demo code.
You can refer the below link for sample for how to write active method COC.
dynamics365musings.com/.../
Your requirement is still not clear. Do you want that when user clicks button, all sales order lines where enum field value is Yes should become non editable and cannot be deleted. Sales lines where enum value is No will remain editable and can be deleted. And I don't understood requirement for denying record creation. Please explain in detail so we can provide you a solution.
In the active method, you can call,
Ds.allowedit(false);
Ds allowdelete(false);
Based on condition.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 687 Most Valuable Professional
André Arnaud de Cal... 535 Super User 2025 Season 2
BillurSamdancioglu 403 Most Valuable Professional