Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to make Sales Line un editable on a button click

(0) ShareShare
ReportReport
Posted on by 100

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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    Can you tell me where did you create an Yes/No enum field.

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    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.

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    Ok Thanks Girish !!

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    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.

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    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.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    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'

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    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.

  • HARISH MEHRA Profile Picture
    HARISH MEHRA 100 on at
    RE: How to make Sales Line un editable on a button click in D365FO

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

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    Have you debugged the code. Check if you are getting values in line# 8 and 9.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: How to make Sales Line un editable on a button click in D365FO

    Have you debugged the code?

    Thanks,

    Girish S

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans