Populate stack name with a script

  • Release version: Australia
  • Updated March 12, 2026
  • 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:

    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 for a comprehensive list of all APIs. See Script Includes 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.

        Changing the scope

        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 Definition > Script Includes.
      5. Click New.
      6. Fill in the form fields (see table):
        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.

        Set fields script include

      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 Design > Blueprints 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:
        Field Description
        Name Provide a meaningful name and description, such as Set Stack Name to User ID.
        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 $(Script:SetFields.setStackName[])

        A script action on StackName

      3. Click Submit.

    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.

    The Logged In User