How to update Resource capacity using background job?

Talya
Tera Contributor

Hi All,

We have created multiple schedules (as per holiday calendar) and associated to users in the user form.

Now I need to update users capacity as per schedule.

Since we have 500+ users, I cannot go to user form and run the UI action ’Update Resource Capacity’ individually.

I want to use the background job 'Update resource capacity' to update all users capacity.

If I want to run the background job for all users (i.e all groups) for whole year, what values should I set in the following script? 

If we are in mid of Jan 2023 and we want to run this job for Jan 2023 to Dec 2023,

1. what value to set for variable runFor?

2. If I want to update capacity for all users then should I include all group names with comma inside includeGroups and leave excludeGroups empty? 

Talya_0-1672440951876.png

Please help,

 

Thanks,

Talya

1 ACCEPTED SOLUTION

Namita Mishra
ServiceNow Employee
ServiceNow Employee

Hi @Talya,

Try using CapacityGenerationAPI to achieve this functionality.

You can update the schedule-wise capacity. In other words you can update the capacity of all the users belonging to a specific schedule in one go.

          Basically CapacityGenerationAPI (System Definition -> Script Include – select CapacityGenerationAPI) is the script include which has the methods to update the capacity for users, or users belonging to specific role or specific group or specific schedule.

 

For example: Execute the method using the background script as shown below

          System Definition -> Scripts - Background -> Background

        var CapacityGenerationAPI = new CapacityGenerationAPI();
CapacityGenerationAPI.updateCapacityAndAvailabilityForSchedules([‘e3140a22eb02010060bbafcef106fe95’], ‘2023-01-01’, ‘2023-12-31’);

 

On execution, this will update the capacity of all the pps_resource users from Jan 01, 2023 to Dec 31, 2023 whose schedule is as per the sys_id of the schedule provided as first parameter.

 

NOTE: I would strongly recommend to keep the date duration for 1 year only. FYI - It is intentionally kept for one year due to performance reasons.. 

------------

How To Get the sys_id of the schedule?

Open the required schedule from left nav bar and on the header (or title bar of that schedule), right click and select copy sys_id.

---------

Yes, to update capacity for all users, include all group names with comma inside includeGroups. These groups need to have pps_resource role.

 

Please mark the response as correct in case your query is resolved. This way you will help other community members in searching the correct answer easily & quickly.

View solution in original post

2 REPLIES 2

Namita Mishra
ServiceNow Employee
ServiceNow Employee

Hi @Talya,

Try using CapacityGenerationAPI to achieve this functionality.

You can update the schedule-wise capacity. In other words you can update the capacity of all the users belonging to a specific schedule in one go.

          Basically CapacityGenerationAPI (System Definition -> Script Include – select CapacityGenerationAPI) is the script include which has the methods to update the capacity for users, or users belonging to specific role or specific group or specific schedule.

 

For example: Execute the method using the background script as shown below

          System Definition -> Scripts - Background -> Background

        var CapacityGenerationAPI = new CapacityGenerationAPI();
CapacityGenerationAPI.updateCapacityAndAvailabilityForSchedules([‘e3140a22eb02010060bbafcef106fe95’], ‘2023-01-01’, ‘2023-12-31’);

 

On execution, this will update the capacity of all the pps_resource users from Jan 01, 2023 to Dec 31, 2023 whose schedule is as per the sys_id of the schedule provided as first parameter.

 

NOTE: I would strongly recommend to keep the date duration for 1 year only. FYI - It is intentionally kept for one year due to performance reasons.. 

------------

How To Get the sys_id of the schedule?

Open the required schedule from left nav bar and on the header (or title bar of that schedule), right click and select copy sys_id.

---------

Yes, to update capacity for all users, include all group names with comma inside includeGroups. These groups need to have pps_resource role.

 

Please mark the response as correct in case your query is resolved. This way you will help other community members in searching the correct answer easily & quickly.

Hi @Namita Mishra ,  Thank you so much for these details. This is very helpful.

 

I will follow the below steps, please let me know if anything is wrong here:

1. I will export the resources (associated to pps_resource role) to Excel and update the 'schedules' and 'Average Daily FTE Hours/Hours Per Person Day' fields. (We have 6 different schedules)

2. I will use the import set and use email field as coalesce and import the excel 

3. I need to run the script CapacityGenerationAPI() 6 times, mentioning sys id of each schedule. 

I will NOT run the 'Update resource capacity' background job.

 

One more related query:

In the resource properties file , if default schedule name is set as 'ScheduleA' , but we have associated 'ScheduleB' to user in user form for USER1. Then which schedule takes the precedence for capacity calculation for USER1?

 

Thanks,

Talya