Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to figure out whic...
Finance forum
Answered

How to figure out which method is used

Posted on by 175
Hi,

In the worker/employee form i have added a new field called OfficeLocation. The Office Address field that you can see to the right of my custom field, is populated when a you assign an address to the worker. I want the same functionality to apply for my new field.




My questions:
  1. Where do I find the method that populates the Office address when an address is assigned.
  2. I have an idea that it might be the InitValue method but I am not allowed to Override any method. Why is that?

I get the following error when I try to override a method
  • CU30040608-0 Profile Picture
    CU30040608-0 175 on at
    How to figure out which method is used
    Hi Layan, 
     
    Thank you for the help again. 

    I am often not able to update posts in this from, so i will have to reference the correct answer here: 

    The answer that solved my problem is was posted byLayan Jwei on 27 Nov 2023 at 21:24:47
  • Layan Jwei Profile Picture
    Layan Jwei 4,815 Super User on at
    How to figure out which method is used
    Hi Community User,
     
    I can see that you closed the other thread. Is this question also fixed?
     
    Thanks,
    Layan Jweihan
  • Layan Jwei Profile Picture
    Layan Jwei 4,815 Super User on at
    How to figure out which method is used
    Hi Community User,

    But we said that you will add the SiteRecId to logisticsPostalAddress. I don't want to mix questions as this thread is only related for assigning site Id when you click "Assign office to location"  -- I add a comment now to your previous question with all steps needed (https://community.dynamics.com/forums/thread/details/?threadid=1a6b14ef-4489-ee11-8179-00224827e5da)

    Now after you finish with the other question, this question is about populating Site Id when you click assign to office location. And I answered that in my previous reply, so If you follow my steps it should work. 

    Please verify the questions that helped you.

    Thanks,
    Layan Jweihan
     
  • CU30040608-0 Profile Picture
    CU30040608-0 175 on at
    How to figure out which method is used
    Hi layan. 

    It is correct that i am able to add Site as a datasource on the DirPArtyPostalAddress Query. But i cant make a relation because i dont have access to a the RecId to match on another table. Because of this i cant make a join. And i guess this is the reason why i get so many duplicates?





    If i Just add the Site table as a datasource i get duplicates (one for each value in my site table). I have tried both outer and inner joins. OneToOne and OneToN. 
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 4,815 Super User on at
    How to figure out which method is used
    Hi Community User,

    In the other thread, I've asked you to add the Site as a datasource to the dirPartyPostalAddress Query and not the view, when you add the datasource to the query, then from the view, you can just drag and drop the SiteName and that's it, as the view contains the query -- please put your questions there and I can help you to have all the answers you need. let's leave the answers here related to the original question.

    Now for this question, here's what you need:

    1. As I told you in the previous reply, you need to add a display method for your siteName similar to the display method for officeLocationAddress (you can enhance the code if you want as I think we can access hcmWorker directly)
    [ExtensionOf(formDataSourceStr(HcmWorker, HcmWorkerTitle))]
    final class HcmWorkerFDS_Extension
    {
        public display str site()
        {          
            DirPartyPostalAddressView officeLocationPostalAddressView;
            HcmWorkerTitle   hcmWorkerTitle = this.cursor();
            hcmworker hcmworker = hcmworker::find(hcmWorkerTitle.worker);
                
            select firstonly SiteId from officeLocationPostalAddressView
                    where officeLocationPostalAddressView.Party == hcmworker.Person
                    && officeLocationPostalAddressView.Location == hcmWorkerTitle.Location;
                
            return officeLocationPostalAddressView.SiteName;
        }
    
    }

    2. You need to add a string control to HcmWorkerV2 form (which is control (SiteName) that you want it to appear in workerSummary) And link it to the display method like this:
     
     
    And that's it, you don't even need to override the "HcmWorkerAssignToOfficeLocation" --- it will work by itself -- at first i thought u want to do certain logic 
     
    Please mark all the answers that helped you as verified. And don't forget to update your previous question https://community.dynamics.com/forums/thread/details/?threadid=1a6b14ef-4489-ee11-8179-00224827e5da

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
  • CU30040608-0 Profile Picture
    CU30040608-0 175 on at
    How to figure out which method is used
    Hi Layan, 

    Sorry. Im not following. Why cant i just create an extension of the HcmWorkerAssignToOfficeLocation method somehow? When i take a look into this method it does not use DirPartyPostalAddressView like you suggets. Also i was never able to add Site as a data source on DirPartyPostalAddressView which is why the following post is still open :(   https://community.dynamics.com/forums/thread/details/?threadid=1a6b14ef-4489-ee11-8179-00224827e5da 

    I am not sure how to create the methods you suggets. Can you specify where and how to create these? 

    I can see that i am able to extend this one


    But if i understand you correct this is not what you want me to do? Sorry. I have never created a method in FO before so the first step is whether is should extend one or if i should create a new and how to do so. :) 
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 4,815 Super User on at
    How to figure out which method is used
    Hi CommunityUser,

    If I understood you correctly, what you need to do is when you click "Assign office to location"  -- you want both the "officeLocation" and "Site" to be filled with the "address" and "Site" fields in the address grid. correct?
     
    So your issue is now with the Site field.
     
    you don't need to add any field to HcmWorkerTitle table, if u noticed this HcmWorkerTitle_postalAddress is linked to a data method and not a field.
     
    So you need to add a control in HcmWorker form "HcmWorkerTitle_Site and link it to a display method (site) and not a field, similar to what was done for officeLocationAddress
    this method will be added to form datasource HcmWorkerTitle using extensions, and you need to put logic for the Site inside it (so you'll return officeLocationPostalAddressView.Site instead)​​​​​​​
     
     
    Make sure you add your Site field to dirPartyPostalAddressView as well

    Then you'll need to create an extension of "LogisticsPostalAddressGrid" Form and add a method (parmSite) similar to the existing below method

     
    Then create extension of "HcmWorkerAssignToOfficeLocation" class and add code in the "run" method -- you'll need the "parmSite" method here -- when you look at the run method you'll understand why

    Hopefully this was helpful enough and u can carry on 

    Also you didn't get back to us on this one
    ​​​​​​​https://community.dynamics.com/forums/thread/details/?threadid=d834bb05-4385-ee11-8179-00224827ee71

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 3,904 on at
    How to figure out which method is used
     
    Can you take a look on this class (HcmWorkerAssignToOfficeLocation) that is called on the HcmWorkerV2 form, and it is set the location field that you are asking about.
     
     
    Regards,
    Waed Ayyad
     
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
     
     
     
     
  • CU30040608-0 Profile Picture
    CU30040608-0 175 on at
    How to figure out which method is used
    Hi,

    I have now added a new field called Site instead of office location (so please ignore that one).

    Here is what I want to do

    The following picture shows the Worker summary form. On the form the Office address Is automatically updated when worker is assigned to an adress from the list in the next picture.



    When I assign Test Address to the worker, the field Office address is updated in the worker Summary form. I want the same functionality for the Site field. So in this example I want Aarhus to be added to the worker summary form.

    What is know so far:
    In the HcmWorkerV2 form that I have extended, I can see that OfficeLocation uses HcmWorkerTitle as a Datasource and OfficeLocationAddress as the data method.  






    What I have done:
    I have extended HcmWorkerTitle and added two EDT’s that (one representing the RecId of the site and one representing the Name of the site). I have then added a relation between the HcmWorkerTitle table and my custom Site table.   


    My problem:
    I am not sure what to do from here to get my Site field working the same way as the Office address field. I am guessing that I should extend some class or method but I am not sure which and how to do it? I read online that I should avoid overriding methods if possible but use extensions instead.
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 4,815 Super User on at
    How to figure out which method is used
    Hi CommunityUser,

    1. How did you add this office address? did you use an existing field and just renamed it? if that's the case, then it's now being filled with the value of the field you dragged. -- Now if you need help with this field, can you please explain to us what you did in the form design and what would u like to fill this office address with?

    2. How are you overriding the initValue method? you should create an extension class and you should open VS as an admin

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans