Your script should include the following:
- Data Selection from that array
- And a property setting using the data from the array
- First, you build the array of desired data. The array will be declared in the script file and will look like this:
var oStrings = ["Value1","Value2"];Arrays require a special format. On the right, an example of declaring a variable named
oStringsand setting its value to an array.
- The data for any array starts with '[' and ends with ']'
- The values inside the array should be wrapped in double quotes
- At the end of a value, you have a comma before the next value
var oStrings = [ "PG3032901074056", "PG3052321074056", "PG3062641074056", "PG3082651074056", "PG3182821075056", ];
- Next, you have to have code that 'selects' or 'chooses' a value from the Array. This extraction will also set the value extracted into another variable.Here 0 is the index for which value we are pulling from the array. This index can be specified or obtained randomly. Arrays use numerical indexes. Usually starting with 0. You can get a value from the array with this syntax:
oStringsThis gets the 0th index from the array. When you pull from the array, you have to specify the index you want from it.Note: If you choose an index that does not exist, you will get an "Index Out of bounds" error.
var getValueFromArray = oStrings;An example of random extraction:
var a = oStrings[Math.floor(oStrings.length * (Math.random()))];
- Once you have chosen the value from the Array, take that selected value into a property that the clip can use.
What you should see
In the example on the right:
MessageClipis the scope of the property, or where it lives.
NameOfPropertyInClipis the name we will use in the Clip to pass this value.
$prop.set("MessageClip", "NameOfPropertyInClip", getValueFromArray);
There are two ways to set properties in CloudTest:
- Seed data such as from an index from an Array or terms to use in a Search
- Extracted Values. Example: After logging into a site, we need to extract data and put that data into a property in order to pass it to all the Messages that come after. For example, a SessionID. See Extract a sessionID for more information about extracted values such as sessionID(s).
In the example on the right, we are setting a clip property with the name of
$prop.set("MessageClip", "scriptSessionId", scriptSessionId);