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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to make Sales Line un editable on a button click

(0) ShareShare
ReportReport
Posted on by 113

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++.

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    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.

  • HARISH MEHRA Profile Picture
    113 on at

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

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    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.

  • HARISH MEHRA Profile Picture
    113 on at

    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 .

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    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.

  • GirishS Profile Picture
    27,827 Moderator on at

    Yes setting datasource.allowedit(false) and allow Delete(flase) at active method will meet your scenario you are expecting.

    Thanks,

    Girish S.

  • HARISH MEHRA Profile Picture
    113 on at

    It should be YesNo value found  on particular Sales line.

    Can you suggest a demo code.

  • GirishS Profile Picture
    27,827 Moderator on at

    You can refer the below link for sample for how to write active method COC.

    dynamics365musings.com/.../

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    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.

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 687 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 535 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 403 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans