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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Sort Fields into a Lookup Form

(0) ShareShare
ReportReport
Posted on by 5

Hi all

I want to add a method into a lookup form to sort the Invoice Date , descending

I want to know if I fill the code in the init or queryexecution?

Im new on D365 , I need also please an exemple from A to Z with the code .

Thank you

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Sort Fields into a Lookup Form

    Hi Goergio,

    You can write code in the data source init method to add the field you want to sort it by (Invoice date in your case). You can check this post for an example.

  • Goergio Profile Picture
    5 on at
    RE: Sort Fields into a Lookup Form

    How I can Override the init() method of data source into a class

    What should I write

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Sort Fields into a Lookup Form

    Which form are you working on? Is it a standard form?

  • Goergio Profile Picture
    5 on at
    RE: Sort Fields into a Lookup Form

    No customized one

    Just please I need exemple any form

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Sort Fields into a Lookup Form

    So, this is a lookup form . Correct?

    You can right click on data source methods  an choose override and select init.

    5224.pastedimage1611169829109v1.png

    You can check the ProjTableLookup form as an example, which has an init method.

  • Goergio Profile Picture
    5 on at
    RE: Sort Fields into a Lookup Form

    And what should I put in my code after I override the method

    Please I need a full code

    Thanks man

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Sort Fields into a Lookup Form

    Since this is a customized form, I am not sure of the datasource and field names. You can follow the post I provided in the beginning.

    Your code will look like this -

    this.queryBuildDataSource().addSortField(fieldNum(, InvoiceDate),SortOrder::Descending);

    You can replace <yourTable> with the table name (that you are using in the data source).

  • Goergio Profile Picture
    5 on at
    RE: Sort Fields into a Lookup Form

    Only I have to add this line of code? And

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Sort Fields into a Lookup Form

    That should be all for sorting by the field.

  • Rafia Mohammed Profile Picture
    266 on at
    RE: Sort Fields into a Lookup Form

    Hi Goergio,

    this.queryBuildDataSource().addSortField(fieldNum(<YourTable>, InvoiceDate),SortOrder::Descending);

    In the place of <YourTable> you place your table name and as you said the field you want to sort is InvoiceDate. So copy the field name and paste it here in the place of InvoiceDate

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,177

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans