Skip to main content

Notifications

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

Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker

(0) ShareShare
ReportReport
Posted on by 54
Hi,
I have a form which has a reference group form control & has a lookup of Dirperson names but it is a int64 field. I want to sort this table records based on alphabetical order of their names.
If I am sorting based on that int64 field then it is sorting based on RecId's only but I want to sort based on the alphabetical order of their names.
I tried code in init method of datasource but it isn't working as expected.
 
 
 
      
        
 
Thanks & Regards,
Rahul
  • Rahul Dahiya Profile Picture
    Rahul Dahiya 54 on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    Hi Martin,
    Thanks for the Solution, I followed your steps & it works perfectly fine.
     
    Thanks & Regards,
    Rahul
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    DirPerson is a child of DirPartyTable and it inherits Name field from DirPartyTable. There is no point in joining DirPartyTable with DirPerson, because you already have the same information in DirPerson and it's actually the same table in database. That's why your condition DirPerson.RecId == DirPartyTable.RecId works - if these were two different tables, the condition wouldn't make sense. Therefore you can simplify your implementation by removing DirPartyTable data source, which also mean less work in the next step.
     
    When you join data sources that you don't want to save, you must explicitly prevent saving. Override validateWrite() and write() methods of these data sources. Neither of them should call super(); validateWrite() should always return true and write() should simply do nothing.
     
    The "Select a record type to create" will disappear when you remove the unnecessary DirPartyTable record. It's happening because the system doesn't know which child of DirPartyTable you want to create.
  • Rahul Dahiya Profile Picture
    Rahul Dahiya 54 on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    Hi Martin,
    Actually name comes from DirPartyTable, I have 4 datasources in my form. first is HSDSMToPC DataSource which has a relation with HCMWorker Table (HSDSMToPC.DSM == HCMWorker.RecId) then HCMWorker has a relation with DirPerson Table (HCMWorker.person == DirPerson.RecId) then in last DirPerson has relation with DirPartyTable DataSource (DirPerson.RecId == DirPartyTable.RecId) & giving outer join on all three child dataSources.
     
    Now I have wrote code on DirPartyTable init method & add sorting on name field like this : 
     
    [DataSource]
        class DirPartyTable
        {
            /// <summary>
            ///
            /// </summary>
            public void init()
            {
                super();
                HSDSMToPC_ds.query().dataSourceTable(tableNum(DirPartyTable)).addSortField(fieldNum(DirPartyTable,Name), SortOrder::Ascending);
            }
    
        }
    after this code, Records has been sorted alphabetically. but it is not allowing me to create new record. whenever I am trying to create a new record. while saving it is throwing error that 'Name is required' but name field is not exist in my table.
    Is it storing record in DirPartyTable?
     
    I also tried to override init method of primary DS 'HSDSMToPC' & wrote same code as above but on UI, its throwing error that Object Reference not set to an instance of an object. 
    firstly it is opening a dialog box after hitting at new button like below: 
     
    & while saving the record it is throwing this error: 
     
     
    thanks & regards,
    Rahul
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    Aha, OK.
     
    If DSM field is the worker RecId, sorting by it naturally sort by RecId values. You'd need to join the table with names and sort by a field in that table. I see you already have DirPerson data source in your form - can't you use it? Of course, I don't know what it's joined or linked to and how.
  • Rahul Dahiya Profile Picture
    Rahul Dahiya 54 on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    Hi Martin,
    yes I have added sorting in my form only bcz I don't want to sort records in HCMWorkerLookup lookup form instead I want to sort records alphabetically in my form.
    This is my form showing below It has a int64 field DSM & has a lookup of DirPerson. I want to sort here like 'Arnie Mondloch' should be on top.
     
        
           & this is the table: 
           
     
    Thanks & Regards,
    Rahul
     
      
  • Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    Sorting records based on DirPerson Name which is a int64 field & has relation with HCMWorker
    It seems to me that you added a range to your own form (where the lookup form is opened from) and not to the lookup form. Or am I confused? Isn't HcmWorkerLookup the right form?

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans