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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

which method is called on updating the role id in project resources under resource list

(0) ShareShare
ReportReport
Posted on by 167

Hi,

Did anyone has idea which method is called on updating the role id in project resources under resource list?

Thanks!!

pastedimage1679291847505v2.png

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi

    Seems Role Id in the Resource list page form is a display method.

    Refer to the display method getResourceCategoryId on ResResourcesListView DataSource of ResResourceListPage form.

    Role Id is fetched from the ResourceResourceCategorySetUp table.

    Thanks,

    Girish S.

  • D365 ER Profile Picture
    167 on at

    Thanks for the reply....my requirement is I have new field as  role id  in HCMEmployment table and on updating or inserting the role Id from ResResourcesListView I want to update the same in HCM employment.

    Suggest me the ways to achieve it as we can't write any insert or update method on views.

    Thanks!!

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    RoleId is not inserted or updated from ResResourcesListView.. Role Id is inserted or updated from ResourceResourceCategorySetup table.

    On the same form you have posted there is a menu item name Resource role. In that form only they will add Rold Id.

    So you can add your code OnInserted and OnUpdated event handler of ResResourceCategorySetupTable to update the RoleId on the HcmEmployment table.

    Thanks,

    Girish S.

  • D365 ER Profile Picture
    167 on at

    Hi Girish ,

    I used the event handler on inserted...But I am getting the below error.

    Cannot create a record in Employment (HcmEmployment). Insert not supported with the values specified for 'Employment start date' and 'Employment end date'. New record overlaps with multiple existing records.

    Let me know if my code is correct.

    select Resource from resourceResourceCategorySetup

             join resourceView

             join hcmEmployment

             where resourceView.RecId == resourceResourceCategorySetup.Resource

             && resourceView.Worker == hcmEmployment.Worker

             && resourceResourceCategorySetup.ValidTo >= today()

                           && resourceResourceCategorySetup.ValidFrom <= today()

      PSASchedRole roleTable1 = PSASchedRole::find(resourceResourceCategorySetup.ResourceCategory);

           hcmEmployment.WERoleId = roleTable1.RoleId;

           if(hcmEmployment)

           {

               hcmEmployment.WERoleId = roleTable1.RoleId;

               hcmEmployment.doinsert();

           }

  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    No need to insert the record. For the selected resource there will be a record in the employment table. You need to do an update on the employment table against that worker.

    [DataEventHandler(tableStr(ResourceResourceCategorySetupTable), DataEventType::Inserted)]
    public static void ResourceResourceCategorySetupTable_onInsertod(Common sender, DataEventArgs e)
    {
        ResourceResourceCategorySetupTable category = sender as ResourceResourceCategorySetupTable;
        PSASchedRole roleTable1 = PSASchedRole::find(category.ResourceCategory);
        ResourceView resource;
        HcmEmployment employment;
        
        select * from resource
            where resource.Resource = category.Resource;
        select forupdate * from employment
            where employment.worker == resource.Worker;
        if(employment)
        {
            ttsbegin;
            employment.WERoleId = roleTable1.RoleId;
            employment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            employment.update();
            ttscommit;
        }
    }
    

    Thanks,

    Girish S.

  • D365 ER Profile Picture
    167 on at

    Hi,

    Thanks for the correction but getting the error while updating.

    Cannot edit a record in Employment (HcmEmployment). Update on a valid time state table is not allowed without specifying a ValidTimeStateUpdateMode.

    Thanks!!

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    You need to mention the ValidTimeStateUpdateMode while updating valid time state tables. Check my code I have added that. Refer to line number 17 on my code.

    Thanks,

    Girish S.

  • D365 ER Profile Picture
    167 on at

    Thanks its resolved.

    Just commented line 17.

  • GirishS Profile Picture
    27,827 Moderator on at

    Please mark the helpful answers as verified, so that others can make use of it.

    Thanks,

    Girish S.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans