Forum Discussion
Will-Painter
Nov 10, 2024Copper Contributor
How to extract the value of RBS in Enterprise Resource in Project Server 2019?
I try to retrieve the value of RBS in Enterprise Resource in Project Server by using C#/ CSOM. Unfortunately, I just got the Resource Name, as for the value of RBS, I always cannot extract any value ...
Wei-Painter
Nov 14, 2024Copper Contributor
Hi Mks_1973,
// Retrieve the full hierarchical path for RBS
var rbsValue = string.Join(" > ", rbsField.LookupEntries.Select(le => le.FullValue));
I just tried it, and I can indeed get all hierarchical path for RBS. Is there a way to retrieve the RBS information related to a specific user?
Thanks - I am new player so I have a lot of questions
Mks_1973
Nov 14, 2024Iron Contributor
Yes, you can retrieve the RBS (Resource Breakdown Structure) information specific to a user by filtering based on the user’s resource ID or their specific criteria in the query.
Here's how you can get the RBS value for a specific user:
// Assuming you have the context and have authenticated
var projectContext = new ProjectContext("https://your-project-server-url/");
// Replace with the user's resource ID
Guid resourceId = new Guid("your-specific-resource-id");
// Retrieve the specific resource by ID
EnterpriseResource specificResource = projectContext.EnterpriseResources.GetById(resourceId);
// Load the resource with custom fields (including RBS)
projectContext.Load(specificResource,
r => r.CustomFields.Include(cf => cf.InternalName, cf => cf.LookupEntries, cf => cf.Value));
projectContext.ExecuteQuery();
// Now, retrieve the RBS field
var rbsField = specificResource.CustomFields.FirstOrDefault(cf => cf.InternalName == "Custom_RBS_Field_Internal_Name");
// If the RBS field exists, retrieve its full hierarchical path
if (rbsField != null && rbsField.LookupEntries != null)
{
string rbsValue = string.Join(" > ", rbsField.LookupEntries.Select(le => le.FullValue));
Console.WriteLine("RBS for the specified user: " + rbsValue);
}
else
{
Console.WriteLine("RBS information not found for the specified user.");
}
======================
Replace "your-specific-resource-id" with the actual resource ID for the user you're interested in.
Replace "Custom_RBS_Field_Internal_Name" with the actual internal name for the RBS custom field in your Project Server instance.
Check if the resource has an RBS assigned. If rbsField.LookupEntries is null or empty, the user might not have an RBS assigned.
- Wei-PainterNov 15, 2024Copper Contributor
Hi Mks_1973,
Thanks. I will give it a try at this first.
- WEISH1195Nov 14, 2024Copper Contributor
Hi Mks_1973,
Thanks once again. I just try the sample code and ran into the error like this: cf.Value >> Error.
Thanks.
- Mks_1973Nov 14, 2024Iron Contributor
This error might happen if Value is not a valid property for the CustomField object in your context.
Through below code you can retrieve the hierarchical RBS path for a specific resource without relying on the cf.Value property:// Assuming you have the context and have authenticated
var projectContext = new ProjectContext("https://your-project-server-url/"); // Update this with your Project Server URL// Replace with the specific user's resource ID
Guid resourceId = new Guid("your-specific-resource-id");// Retrieve the specific resource by ID
EnterpriseResource specificResource = projectContext.EnterpriseResources.GetById(resourceId);// Load the resource with custom fields (including RBS) and ensure lookup entries are included
projectContext.Load(specificResource,
r => r.CustomFields.Include(cf => cf.InternalName, cf => cf.LookupEntries));
projectContext.ExecuteQuery();// Retrieve the RBS field based on its internal name (replace with actual internal name for RBS in your setup)
var rbsField = specificResource.CustomFields.FirstOrDefault(cf => cf.InternalName == "Custom_RBS_Field_Internal_Name");// If the RBS field exists, retrieve its full hierarchical path
if (rbsField != null && rbsField.LookupEntries != null && rbsField.LookupEntries.Count > 0)
{
string rbsValue = string.Join(" > ", rbsField.LookupEntries.Select(le => le.FullValue));
Console.WriteLine("RBS for the specified user: " + rbsValue);
}
else
{
Console.WriteLine("RBS information not found for the specified user.");
}
==================================
Changes in Above:Since cf.Value seems to be causing an error, I omitted it. Instead, we rely solely on LookupEntries to fetch the hierarchical path.
Added rbsField.LookupEntries.Count > 0 to ensure there are entries to process, which should prevent null reference errors.
Update "https://your-project-server-url/" with your Project Server URL.
Update "your-specific-resource-id" with the actual resource ID for the user.
Replace "Custom_RBS_Field_Internal_Name" with the exact internal name for the RBS field in your Project Server.
If the InternalName for the RBS field is unclear, you may need to inspect your custom fields in Project Server to ensure you're referencing the correct internal name.
Please remember that LookupEntries only works if the RBS field uses a lookup table with hierarchical values.