Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Enable / disable fields of selected line in salesline table based on check box value.

(1) ShareShare
ReportReport
Posted on by 27
class SalesTable_SalesLine_AgreedPrice_EventHandler
{
 
    [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, AgreedPrice), FormDataFieldEventType::Modified)]
    public static void AgreedPrice_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        FormRun formRun = sender.datasource().formRun();
        FormDataSource SalesLine_DS = formRun.dataSource(formdatasourcestr(SalesTable, SalesLine)) as FormDataSource;
        SalesLine sales_line = SalesLine_DS.cursor();
    
            SalesLine Sales_Line_Selected = SalesLine::findRecId(sales_line.RecId);
                if(Sales_Line_Selected.AgreedPrice == NoYes::No)
            {
               
               SalesLine_DS.object(fieldNum(SalesLine, SalesPrice)).enabled(false);
            SalesLine_DS.object(fieldNum(SalesLine, LinePercent)).enabled(false);
            SalesLine_DS.object(fieldNum(SalesLine, LineDisc)).enabled(false);
            SalesLine_DS.refresh();
            }
            else
            {
                SalesLine_DS.object(fieldNum(SalesLine, SalesPrice)).enabled(true);
            SalesLine_DS.object(fieldNum(SalesLine, linedisc)).enabled(true);
            SalesLine_DS.object(fieldNum(SalesLine, LinePercent)).enabled(true);
            SalesLine_DS.refresh();
            }
     
    }
}

this code enable and disable all lines not a a single line in salesline table based on agreedprice chackbox value
can anyone guide me where is the issue?
if i write the code 
  Sales_Line_Selected.datasource().object(fieldNum(SalesLine, SalesPrice)).enabled(true); // this line through error object reference not set to an instance of an object
i did'nt find any solution .
i also wrote code in active method and selectionchanged method of form datasource (salesline)but results are the same
thank you
 
  • Dyn_US Profile Picture
    Dyn_US 27 on at
    Enable / disable fields of selected line in salesline table based on check box value.
    @Martin Dráb thank you so much. May God bless you more.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,579 Most Valuable Professional on at
    Enable / disable fields of selected line in salesline table based on check box value.
    That's correct. If you disable a field, it's disabled for all rows (but you always work with the single active one anyway).
     
    If you want to evaluate the condition again when switching to another row, call your logic from active() method of SalesLine data source. I can't say for sure what mistake you made when you tried it, but giving up the right approach isn't a good idea. Instead, you need to find your bug there. One possible reason is that you forgot to take the standard logic of the form into account. You can't simply set SalesPrice as enabled or disabled; there is existing logic for the same. If you do it before the standard logic, your code will have no effect. If you do it after, you'll break the standard logic (e.g. you'd allow editing even if RetailSalesLine.IsPriceLocked is true).
     
    Don't call refresh(); it's not needed in your scenario.
     
    By the way, you can get the data source in the event handler by calling sender.dataSource().

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

Congratulations 2024 Spotlight Stars!

Kudos to all of our 2024 community stars!

Meet the Top 10 leaders for December!

Congratulations to our December super stars!

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,559 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,579 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans