web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

marking a field as true or false for all records

(1) ShareShare
ReportReport
Posted on by 252
Hi,

i have an action menu item  on salesLine grid, when clicked, it selects a custom field as yes for all lines or no for all other lines

How would you rewrite this code?

is this line good:
if(_args && _args.record() && _args.dataset() == tableNum(SalesLine))

and what is inside method  'updateSalesLineSelection' to refresh form datasource, is what i did correct? (i know it's working but i want to know if the code can be better)

public class SelectOrDeselectAllLines
{

    public static void main(Args _args)
    {
        if(_args && _args.record() && _args.dataset() == tableNum(SalesLine))
        {
            SelectOrDeselectAllLines selectOrDeselectAllLines= SelectOrDeselectAllLines::construct();
            SelectOrDeselectAllLines.updateSalesLineSelection(_args.record());
        }
    }


    public void updateSalesLineSelection(SalesLine _salesLine)
    {
        if (_salesLine)
        {
            FormDataSource salesLineDataSource = FormDataUtil::getFormDataSource(_salesLine);

            if (salesLineDataSource)
            {
                this.selectionChanged(_salesLine.SalesId, !_salesLine.FieldX);
            }

            salesLineDataSource.research(true);
        }
    }

   
    public void selectionChanged(SalesId _salesId, NoYesId _select)
    {
        SalesLine salesLine;

        ttsbegin;

        update_recordset salesLine 
            setting FieldX                  = _select
            where  salesLine.SalesId        == _salesId 
                && salesLine.FieldX         != _select;

        ttsCommit;
    }


    public static SelectOrDeselectAllLines construct()
    {
        return new SelectOrDeselectAllLines();
    }

}
 
  • Raj Borad Profile Picture
    1,588 on at
    You can try below code, but I didn't test it.
    Hope it will work as per your requirement.
     

        public static void main(Args _args)
        {
            if (_args && _args.record() && _args.dataset() == tableNum(SalesLine))
            {
                SalesLine salesLine = _args.record() as SalesLine;
                if (salesLine)
                {
                    SelectOrDeselectAllLines::construct().updateSalesLineSelection(salesLine);
                }
            }
        }
       
     
    Thank you,
    Raj D Borad.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 511 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 426 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 159

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans