Function RunHierarchicalSurvey(arrChildren As QuestionArray,resParent as PortfolioItem,resPortfolio as Portfolio,ClonedPortfolio As Portfolio) As Boolean Dim nQuestion As Number Dim arrScale4= Survey.Questions.FilterByTag("Scale4") Dim arrScale5= Survey.Questions.FilterByTag("Scale5") Dim arrNPS= Survey.Questions.FilterByTag("NPS") For nQuestion = 1 to arrChildren.Count Dim currQuestion = arrChildren[nQuestion] Dim resItem As PortfolioItem If currQuestion.Type = "chapter" And not(currQuestion.IsDeveloped and currQuestion.Type = "chapter") Then If currQuestion.ChildQuestions.Count > 0 Then resItem.SetType(0) resItem.SetTitle(currQuestion.Shortcut) resPortfolio.Add(resItem, resParent) RunHierarchicalSurvey(currQuestion.ChildQuestions, resItem, resPortfolio, ClonedPortfolio) Endif Else If (currQuestion.IsDeveloped = True) or (currQuestion.IsDeveloped = false) Then 'Dim arrColQuestions = Survey.Questions.FilterByTag("Demographics") resItem.SetType(1) resItem.SetTitle(currQuestion.Shortcut) If currQuestion.Type = "single" Then If arrNPS.FindByShortcut(currQuestion.Shortcut).Shortcut <> "" Then resItem.SetTabDef(ClonedPortfolio.Items[4].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(ClonedPortfolio.Items[4].TabDef.Rows.Clone(currQuestion)) ElseIf arrScale5.FindByShortcut(currQuestion.Shortcut).Shortcut <> "" Then resItem.SetTabDef(ClonedPortfolio.Items[6].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(ClonedPortfolio.Items[6].TabDef.Rows.Clone(currQuestion)) ElseIf arrScale4.FindByShortcut(currQuestion.Shortcut).Shortcut <> "" Then resItem.SetTabDef(ClonedPortfolio.Items[5].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(ClonedPortfolio.Items[5].TabDef.Rows.Clone(currQuestion)) Else resItem.TabDef.Rows.Add(ClonedPortfolio.Items[1].TabDef.Rows.Clone(currQuestion)) resItem.SetTabDef(ClonedPortfolio.Items[1].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(currQuestion) Endif resItem.TabDef.Columns.Clear() resPortfolio.Add(resItem,resParent) ElseIf currQuestion.Type = "multiple" Then resItem.SetTabDef(ClonedPortfolio.Items[2].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(currQuestion) resPortfolio.Add(resItem, resParent) ElseIf currQuestion.Type = "numeric" Then resItem.SetTabDef(ClonedPortfolio.Items[3].TabDef) resItem.TabDef.Rows.Clear() resItem.TabDef.Rows.Add(currQuestion) resPortfolio.Add(resItem,resParent) EndIf 'resItem.TabDef.Columns.Clear() 'resItem.TabDef.Columns.Add(arrColQuestions[1]) Endif RunHierarchicalSurvey(currQuestion.ChildQuestions, resParent, resPortfolio, ClonedPortfolio) EndIf Next nQuestion End Function ' It starts here! Dim resPortfolio As Portfolio Dim ClonedPortfolio As Portfolio ClonedPortfolio.Read("C:\ProgramData\Askia\Clones\TPforScripts.xml",True) Dim resParent As PortfolioItem RunHierarchicalSurvey(Survey.ChildQuestions,resParent,resPortfolio ,ClonedPortfolio) resPortfolio.Save(Survey.Directory + "Tp.xml") resPortfolio.Open()