Copy titles from all children of one group to another

Updated at December 3rd, 2020

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. 


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 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. 


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. 


Was this article helpful?