Example resource pool that limits choices to cost center
Summarize
Summary of Example resource pool that limits choices to cost center
This example demonstrates how to use resource pools with blueprints in ServiceNow’s cloud catalog to restrict the selection of cost centers based on the requesting user's association. This ensures that cloud asset costs are charged only to the user’s designated cost center, enforcing budget control at the request level.
Show less
Key Features
- Resource Pools and Filters: The
UserCostCenterscript filter dynamically limits the cost center choices to the one associated with the ordering user, while theAllfilter allows selection from all cost centers. - Blueprint Integration: Cost center selection is configured within the blueprint’s variables. The
CostCentervariable uses the resource pool and filter to enforce the limitation on the cloud catalog request form. - Prerequisites: The Cost Management plugin must be active, cost centers must be defined and linked to users, and relevant blueprints (e.g., AWS Virtual Server) should be set up. Administrative roles and scripting knowledge are required for customization.
- Script Logic: The provided JavaScript code retrieves the cost center linked to the current user and returns it as the only selectable option in the request form.
How to Test and Modify
- Testing: Impersonate a user associated with a cost center and verify that only their cost center appears as an option in the cloud catalog request form.
- Modifying Filters: Administrators can change the resource pool filter from
UserCostCentertoAllin the blueprint’s variable settings to allow all cost centers to appear, enabling broader selection.
Benefits for ServiceNow Customers
By implementing this resource pool configuration, customers can:
- Ensure cloud resource costs are allocated accurately to the correct cost centers.
- Enhance governance and budget control by restricting user selections based on organizational structure.
- Maintain flexibility by easily switching filters to broaden or narrow cost center choices as needed.
You can use resource pools with blueprints to limit the choices on the cloud catalog request form.
Use case: Restrict cost center selection
In this example, the cost of the cloud asset is charged against the budget of the cost center of the user. The base-system UserCostCenter resource pool ensures that a user can select only resources in their cost center.
Assumptions
- The Cost Management [con.snc.cost_management] plugin is active.
- Cost centers are defined and users are associated with the cost centers.
- At least one blueprint is defined. This example uses a blueprint named AWS Virtual Server.
- You are assigned the sn_cmp_cloud_admin role and know JavaScript and JSON scripting.
Components
- Review resource pool filter
- On the Cloud Admin portal navigate to .
- Open the CostCenterPool and review the related Resource
Pool Filters.
- All is a query filter that returns all cost centers in the table.
- UserCostCenter is a script filter that looks up the cost center associated with the user who is ordering the item.
Here is the script for the UserCostCenter filter:getFilteredRecords(); //Do not remove function declaration /** * @returns filtered records in the format [{"value"="lookupValue",label="displayValue"}] */ function getFilteredRecords() { var filteredRecords = []; var userId = gs.getUserID(); var userGr = new GlideRecord('sys_user'); if (userGr.get(userId)){ var costCenterId = userGr.getValue('cost_center'); if (costCenterId){ var costCenterGr = new GlideRecord('cmn_cost_center'); if (costCenterGr.get(costCenterId)){ var costCenter = {}; costCenter.value = costCenterGr.getUniqueValue(); costCenter.label = costCenterGr.getValue('name'); filteredRecords.push(costCenter); } } } //force to string return new global.JSON().encode(filteredRecords); }
- Blueprint catalog form parameters
- Navigate to , and then click the tile for the blueprint you want to open.
- With the blueprint in Draft state, click the
Provision operation tile on the tab.
- In the Variable sets related list, click the General Info variable set. By default, the CostCenter variable is in this variable set.
- In the Cloud Variables related list on the Variable Set form, click the
CostCenter variable.
- On the Cloud Variable form, click the Type Specifications tab.
- Look at the Pool and Pool Filter
fields that refer to the resource pool and filter.
- CostCenterPool is the name of the resource pool.
- UserCostCenter is the filter script that pulls in the cost center options for the user to select from.
- Set the blueprint to Published.
- Cost center user
- Identify a user who is a member of a cost center and who has access to the Cloud User Portal.
Testing the resource pool filter
After reviewing the components that comprise this use case, test the cloud catalog item to verify that users can select only their cost center.
- Impersonate the user, Alene Rabeck in this example.
- On the Cloud User Portal, click Launch a Stack, and then select the cloud catalog item (AWS Virtual Server in this example).
- Review the selections in the Cost Center list.
With the CostCenterPool::UserCostCenter datasource value for this catalog item, the only option for the Cost Center is the cost center the user is a member of.
Changing the resource pool filter
Test that the resource pool filter is controlling the behavior of the Cost Center field by changing it and viewing the results.
- On the Cloud Admin Portal, navigate to and then click AWS Virtual Server.
- Click the Provision operation tile.
- In the Variable sets related list, click the General Info variable set. By default, the CostCenter variable is in this variable set.
- In the Cloud Variables related list on the Variable Set form, click the CostCenter variable.
- On the Cloud Variable form, click the Type Specifications tab.
- Edit the Pool filter field to change the filter from
UserCostCenter to All.
- Click Update, then clickPublish..
- Impersonate the user, Alene Rabeck in this example.
- On the Cloud User Portal, launch a stack, and then select AWS Virtual Server.
- Verify that all cost centers are listed.