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 , When I click that UI action, It will ask for "start date" and "End date"

 

DhathriC_0-1767969530643.png

In my case, I want to input "Start Date" as Current date, "End Date" as Current Date + 18 months.

@DhathriC 
then you need to check how that UI page calls the backend script include and how it passes those 2 dates

I already shared the details above what to deep dive.

💡 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