Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

how to run "Update Resource Capacity" UI action from backgroud script

DhathriC
Tera Contributor

I want to run "Update Resource Capacity" UI action from background script. I will be passing user id, start date as current date, end date as current date+18 months.

 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@DhathriC 

something like this

var userSysId = 'YOUR_USER_SYS_ID'; // Replace with actual user sys_id
var startDate = new GlideDateTime(); // Today
var endDate = new GlideDateTime();
endDate.addMonthsLocalTime(18);

var CapacityGenerationAPI = new CapacityGenerationAPI();

// Method 1: Update single user (recommended)
CapacityGenerationAPI.updateCapacityAndAvailabilityForUsers([userSysId], startDate, endDate);

gs.info('Resource capacity updated for user: ' + userSysId + ' from ' + startDate + ' to ' + endDate);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@DhathriC 

something like this

var userSysId = 'YOUR_USER_SYS_ID'; // Replace with actual user sys_id
var startDate = new GlideDateTime(); // Today
var endDate = new GlideDateTime();
endDate.addMonthsLocalTime(18);

var CapacityGenerationAPI = new CapacityGenerationAPI();

// Method 1: Update single user (recommended)
CapacityGenerationAPI.updateCapacityAndAvailabilityForUsers([userSysId], startDate, endDate);

gs.info('Resource capacity updated for user: ' + userSysId + ' from ' + startDate + ' to ' + endDate);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

This script works , it runs only for resource managers.

DhathriC
Tera Contributor

@Ankur Bawiskar 

 

When I click "Update Resource Capacity" from UI action. It creates data in "Resource aggregate weekly" and "Resource Aggregate Monthly" tables. when I run the background script I'm not seeing data in these tables. I want to replicate exact steps what is done in the UI action

@DhathriC 

that UI action calls UI page and a script include via GlideAjax

you need to understand what's being passed etc and how

AnkurBawiskar_0-1767968877606.png

 

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader