Copy titles from all children of one group to another

If you have a group of child elements that need title text, you can programmatically copy titles over from a different group that has the same titles.  

In the example below Q15v2's child elements are missing title text that Q14v2's children already have. 

Two horizontal bar charts comparing "Q14v2" and "Q15v2" questions, both asking "What percent of your Condition X/Y patients receiving a GA (gamma antagonist) would receive" with "Compact to Mean" shown. Q14v2 lists products like "New XR Product B" (41.5), "Product D" (23.9), etc., while Q15v2 shows similar items labeled as "Q15v2_1" (36.1), "Q15v2_2" (23.0), etc.

The code below runs through an array and sets each element title by getting the title from a different element. 

This will only work if the child elements of both groups use a similar naming convention. [1, 2, 3, 4, 5, 6, 7, 96] is an array that lists each suffix for the child elements of the groups. In "function(c)" the c represents the array, and the function will run through each value in that array. ("Q15v2_"+c).set represents the element that is missing the titles, and ("Q14v2_"+c).get references the elements from which you will copy the titles. 

Code

[1, 2, 3, 4, 5, 6, 7, 96].forEach(function(c){

    protobi.getDimension("Q15v2_"+c).set('title',protobi.getDimension("Q14v2_"+c).get('title'))

})

 

Open up the developer's console on your browser window and enter the example code above (edit to fit your specific case). Press enter on your keyboard to run the code. 

Protobi interface displaying browser developer console on the right side with JavaScript code visible: "[1, 2, 3, 4, 5, 6, 7, 96].forEach(function(c){ protobi.getDimension(\"Q15v2_\"+c).set('title',protobi.getDimension(\"Q14v2_\"+c).get('title'))})". The left side shows survey questions Q14v2 and Q15v2 with product comparison data.

The group with missing titles should now have the titles copied over from the other group. If you do not see the results, try pressing "r" on your keyboard to refresh the view. 

Two horizontal bar charts showing Q14v2 and Q15v2 with identical product labels: both now display "New XR Product B", "Product D", "Product B", "Product F", "Product C", "Product A", "Product E", and "other" with their respective percentage values. The right side shows Console code: "protobi.getDimension(\"Q15v2_\"+c).set('title',protobi.getDimension(\"Q14v2_\"+c).get('title'))}}" with "undefined" result.