Using PSAResourceTable in Dynamics AX Project Management and Accounting Module
The PSAResourceTable is used often in the Project Management & Accounting module. It holds a list of valid worker resources and is used when assigning workers to tasks. What isn't immediately clear is how to use it. The first problem is that it is used like a temp table, but it isn't defined as a temp table. Instead, it has a Guid field called UserSesssion that controls who will see the records. You also won't easily find any insert statements inserting records into the table. That is where the ProjProjectResourceList class comes in. This class is responsible for populating the PSAResourceTable and deleting the records when you are done.
To see this in action you will first need to add some workers as project resources. Go to Project management and accounting/Common/Project resources/Resources and click the Resource button on the Action Pane.
Add a few resources by choosing appropriate values for each field and press OK. When you are done you should see something like this.
Now we can query the PSAResourceTable for our resources.
private void findResources()
{
PSAResourceTable resources;
HcmWorker hcmWorker;
ProjIProjectResourceList resourceList;
guid userSession;
utcDateTime startDateTime;
utcDateTime endDateTime;
// This Guid is used to filter the table to just our results.
userSession = newGuid();
// Construct the ProjProjectResourceList
resourceList = ProjProjectResourceList::construct(userSession);
// These dates are used to filter the workers
startDateTime = DateTimeUtil::getSystemDateTime();
endDateTime = DateTimeUtil::maxValue();
// Populate the PSAResourceTable
resourceList.getResources(startDateTime, endDateTime);
// Now we can query the table for our resources.
while select Resource, ResourceCalendar, ResourceDataArea, LegalEntity from resources
where resources.UserSession == userSession
&& resources.ResourceSet == ProjResourceSet::Cache
join HcmWorker
where HcmWorker.RecId == resources.Resource
{
info(HcmWorker.name());
}
// Our records will remain in the table until we clear them out because this
// isn't a real temp table.
resourceList.clearResources();
resourceList.clearResourceSet();
}
Make sure you call clearResources and clearResourceSet when you are finished with the table so you don't pollute it with orphaned records.
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.