Problem retrieving planning groups

Hello all. I'm using the WFM api to pull short term forecasts. Part of what I'm trying to do is call an api to also get the name of the planning group in that forecast but I'm running into some issues that I don't understand at this point.

I call GetWorkforcemanagementBusinessunitWeekShorttermforecastData() to get the forecast data for the business unit and use that result when calling GetWorkforcemanagementBusinessunitPlanninggroup() to get the planning group information. But when I call that API I get the following exception

Error calling GetWorkforcemanagementBusinessunitPlanninggroup: {"message":"Entity not found: name = PlanningGroup, id = ","code":"wfm.entity.not.found","status":404,"messageParams":{"uniqueErrorKey":"wfm.entityNotFound.planningGroup","subErrorKey":"PlanningGroup","property":"PlanningGroup","id":""},"contextId":"d73560ef-6f7e-48b0-92d7-877d53ea8db0","details":[],"errors":[]}

When I look in the debugger the planning group id is in the response from GetWorkforcemanagementBusinessunitWeekShorttermforecastData() so I'm not understanding why this is occurring. A snip from my code.

                            BuForecastResultResponse forecastResultResponse = WfmapiInstance.GetWorkforcemanagementBusinessunitWeekShorttermforecastData(WFMresult.Entities[iBuIndex].Id, weekDateId, sForeCastId, iWeekIndex, forceDownloadService);
                            
                            for (int iPgIndex = 0; iPgIndex < forecastResultResponse.Result.PlanningGroups.Count; iPgIndex++)
                            {
                                PlanningGroup resultPg = WfmapiInstance.GetWorkforcemanagementBusinessunitPlanninggroup(WFMresult.Entities[iBuIndex].Id, forecastResultResponse.Result.PlanningGroups[iPgIndex].PlanningGroupId);
                                keyValuePairsPg.Add(forecastResultResponse.Result.PlanningGroups[iPgIndex].PlanningGroupId, resultPg.Name);
                            }

Thanks in advance

Hey, thank you for reaching out.

It appears the planning group you're trying to fetch has been deleted since the forecast was created.

When a short term forecast is created, the planning groups are "snapshotted" at the time of creation, and that snapshot is stored as part of the forecast. This is to prevent modifications (or, in this case, deletions) of planning groups from breaking the forecast. The route you want to call to get the planning groups in use on the forecast is GET /api/v2/workforcemanagement/businessunits/{businessUnitId}/weeks/{weekDateId}/shorttermforecasts/{forecastId}/planninggroups

To add some additional clarification:

The route you're calling (GET /api/v2/workforcemanagement/businessunits/{businessUnitId}/planninggroups/{planningGroupId}) is intended for the current state of a planning group and may not be the same as the planning group in use in the forecast.

It is also worth noting that fetching the planning groups one at a time in a loop is inefficient and likely to be rate limited if you have a lot of planning groups - if you need details on the current state of more than one planning group, it is much more efficient to call the list route (GET /api/v2/workforcemanagement/businessunits/{businessUnitId}/planninggroups)

Hi Brian,

Thank you for that. It explains what I'm seeing. Also I had already modified the code to not get the planning groups in a loop. That loop was just a test to see if I got different results (more of a desperation move at the time).

Regards.

Sure thing, glad I was able to help out!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.