Vipin Tiwari
ServiceNow Employee
ServiceNow Employee

SetValueByScript.

UseCase : Need to set value for stackName as Stack_<Vlue for NodeName> attribute.

Examples :
If NodeName is “acpNode01”
StackName should be “Stack_acpNode01”

When the user will change the nodeName, stackName should get updated automatically.

Solution : We can achieve this using SetValueByScriptAction

SetValueByScriptAction : Action provides you a feature to call any script includes the function and you can return the value which you want to set it in Form Field.
(Make sure script include must be created in sn_cmp scope)

1. You need to create one script include like.
PopulateStackName.
2. Create one method in script include with one paremeter
See getStackName method defined below

    var PopulateStackName = Class.create();
    PopulateStackName.prototype = {
    initialize: function() {
    },

    getStackName: function(stack_name) {
       return "Stack_"+stack_name;
    },

    type: 'PopulateStackName'
    };

3. Now as you already created Script Includes and method you want to call from the action.
4. Navigate to Blueprint --> Form --> Form Parameter.
5. Click on NodeName attribute of Virtual Server Resource
It will be named as <Aliad For Virtual Server>_NodeName.
Like : Virtual_Server_NodeName
6. Scroll down to see the rules defined for this parameter.
7. Click on New buttons in rule
8. Fill the value like Name, SourceFiled, Order and Event. Like below

9. Click on Action tab below.
10. Click on new buttons
11. Fill the following values for Action


As you can see in image you don’t need to specify datasource for SetValueByScript function.
12. Specify Name and ActionType as “SetValueByScript”.
13. Target Field as “StackName”

 


14. Value should be expression like below
$(Script:PopulateStackName.getStackName[arg=${parameter.Virtual_Server_NodeName}])

 

Please validate below checks.


1. Script must start with “$(Script:”
2. PopulateStackName<script>.getStackName<Method defined in script include>
3. [arg=${parameter.Virtual_Server_NodeName}]
You need to define parameter for method you can have multiple parameters like below
4. [arg=${parameter.Virtual_Server_NodeName},
arg=${parameter.Virtual_Server_NodeValue}]

Version history
Last update:
‎09-17-2019 01:39 AM
Updated by: