---
sourceDocument: Yokohama IT Operations Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/yokohama/it-operations-management

 Release :

    - yokohama

ft:locale :

    - en-US

ft:publication_title :

    - Yokohama IT Operations Management

ft:clusterId :

    - itom

bundleId :

    - itom

workflow :

    - Technology


---

# Populate stack name with a script

# Populate stack name with a script {#ariaid-title1}

* Release version: Yokohama
* 
* Updated January 30, 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

This example illustrates how to populate the name of the stack that a user requests
from the Cloud Provisioning and Governance catalog by utilizing the user's ID. The
example uses a script include that you can call from a blueprint rule action.

## Before you begin

Role required: sn_cmp.cloud_service_designer  
Before you can follow this example, you should be familiar with creating blueprints and blueprint rules. See these resources:

* [Cloud Provisioning Blueprints](https://servicenow-prod.fluidtopics.net/sa6wT_Zb5dIhb3bBAk43iA "A blueprint is a specialized catalog item template for offering cloud services, or stacks, to cloud users. Blueprints work with any cloud service provider, such as Amazon AWS Cloud or Microsoft Azure Cloud. Blueprints are in restricted usage from the Orlando release.")
* [Build a Cloud Provisioning blueprint](https://servicenow-prod.fluidtopics.net/EFg~MX6L_NVB5~4R31bKpg "Use the blueprint designer to create custom blueprints for the Cloud Provisioning and Governance application. Blueprints are deprecated in the Orlando release.")
* [Configure a blueprint rule](https://servicenow-prod.fluidtopics.net/mkV44JlrjQeHD3mu5wOJqQ#configure-a-blueprint-rule "Configure a rule that contains actions the system can take on blueprint attributes.")
{#populate-stack-name-example__ul_jb3_hc4_p2b}

This example uses a script include. If you want to create similar script includes,
familiarize yourself with the Glide System APIs that are part of your instance. See
the [Developer site](https://developer.servicenow.com) for a comprehensive list of all APIs. See [Script Includes](https://www.servicenow.com/docs/access?context=c_ScriptIncludes&version=yokohama&pubname=yokohama-api-reference&ft:locale=en-US) for more information about how the
system uses these scripts.

## About this task

The goal of this example is to take the ID of the catalog requester and populate it
in the Stack Name field. The field remains editable. Follow an example like this one
when you want to loosely enforce a naming or labeling convention on certain values,
but still allow the user to enter the text that they want.

## Procedure

1. Create a script include that returns the user ID of the person requesting the catalog item:
   1. In the standard interface for the instance (not in the Cloud Admin Portal), click the gear icon (![System settings gear icon]()) in the upper left, and then click Developer.
   2. In the Application field, select Cloud Provisioning and Governance.  
      The application scope of your instance changes toCloud Provisioning and Governance. This selection means
      that the Cloud Provisioning and Governance application can find
      the script include.
   3. Close the System Settings window.
   4. Navigate to System DefinitionScript Includes.
   5. Click New.
   6. Fill in the form fields (see table):  
      {#populate-stack-name-example__table_vzw_1qw_q2b__entry__2}

      | Field | Description |
      |-|-|
      | Name | Provide a descriptive name without spaces. |
      | Accessible from | Select All application scopes. |
      | Script | Enter this script: |
      | var SetFields = Class.create(); SetFields.prototype = { initialize: function() { }, setStackName: function(){ return gs.getUserName(); }, type: 'HideFormAttributes' }; ||
      | The function `setStackName()` returns the user name of the catalog item requester. You can call this function from a blueprint rule action. ||
      [ ]

      {#populate-stack-name-example__table_vzw_1qw_q2b}

   7. Click Submit.
   8. Click the gear icon (![System settings gear icon]()) in the upper left again, and then change the Application back to Global.
2. In the Cloud Admin portal, navigate to DesignBlueprints and open the relevant blueprint.
3. On the blueprint form, click the Catalog tab, and then click the tile that represents the Provision operation.  
   ![Catalog item]()
4. Click the Stack Name variable set in the Variable Sets related list.  
   Notice that Stack Name is a single line text field that takes text input.
5. Create a rule to populate the stack name:
   1. Scroll down to the bottom of the form and click New in the Rules related list.
   2. Provide a name and description.
   3. Click Submit.
6. Configure the action as follows:
   1. From the Rule form, scroll down and click New in the Action related list.
   2. Configure the rule as follows:  
      {#populate-stack-name-example__table_tgy_xlw_q2b__entry__2}

      | Field | Description |
      |-|-|
      | Name | Provide a meaningful name and description, such as <kbd class="ph userinput">Set Stack Name to User ID</kbd>. |
      | Action Type | Select SetValueByScript to tell the system to call the script include that you specify in the Value field. |
      | Target Variable | Select StackName to tell the system to set the value of the Stack Name field. |
      | Value | Call the method in the script include that returns the user ID. The call must be in the following syntax: `$(Script:ScriptIncludeName.methodName[])` In this example, use <kbd class="ph userinput">$(Script:SetFields.setStackName[])</kbd> |
      [ ]

      {#populate-stack-name-example__table_tgy_xlw_q2b}

   3. Click Submit.
{#populate-stack-name-example__steps_npw_1d4_p2b}

## Result

In the Cloud User Portal, the catalog order form for the Provision operation shows
the user ID of the logged-in user. This example uses the user Able Tutor, which
comes in the base system as demo data. The value in the Stack Name field is the same value as in the User ID field on the User
\[sys_user\] table. The profile icon for the same logged in user is also displayed in
the upper right of the Cloud User Portal.

*[\>]: and then


