Changing Clip Element Names recursively using JavaScript

Document created by Dave Murphy Employee on Jul 19, 2017Last modified by Dave Murphy Employee on Jul 19, 2017
Version 2Show Document
  • View in full screen mode

In certain situations there may be a need to change names of Clip elements.  This could be due to the fact that a clip may be using dynamic data where a message is sent to different urls based on the data. 

 

Example:  You have a clip that extracts a list of categories from the home page into an array.  The clip then loops through the array of categories and loads each category page.  As a result, the url of each category page will be different (i.e http://xyz/cars, http://xyz/bikes...).  However, the name of each page element will remain the same during playback.  The name of the page element will be set to whatever was captured during clip creation process.  The analytics porion of your test, therefore, will not reflect correctly how many times each different category was accessed during the test.  It will appear as if only one category was accessed.

 

In a situation like this, you will want to dynamically change the name of your page (an possibly other elements) at runtime.

 

This kind of renaming can be performed with a JavaScript function shown below:

 

function renameItem(type,name,newName,entryPoint) {
   var children = entryPoint.children;                 

 for (i in children) {                         

 if (children[i].type == type && children[i].name == name) {                                 
 //Item found.  Will rename.
 //$context.result.postMessage($context.result.LEVEL_INFO, "match found : name = " + children[i].name + " type = " + children[i].type);                                 

 children[i].name = newName;     

 } else if (children[i].children) {                                 

 //need to go one level deeper                
 renameItem(type,name,newName,children[i]);                             
 }                   
 }           



renameItem('Group','Group 1','Froggy',$context.currentClip);
renameItem('Transaction','Transaction 1','Spanky',$context.currentClip);
renameItem('Page','Page 1','Alfalfa',$context.currentClip);
renameItem('Message','Message 1','Buckwheat',$context.currentClip);

 

 Function renameItem() takes 4 parameters:

1.  Element type (Message, Page, Transaction, Group, Chain, etc)

2.  Name of Element to be renamed

3.  Name the Element will be renamed to

4.  Entry Point of Search (this has to be set to either the element the JavaScript is a child of, or the clip element).

 

Example of what your clip could look like with JavaScript Renaming:

 

 

 

Example of what your composition could look like after execution:

 

Attachments

    Outcomes