0

I have a tree composed by two main elements: folder (containers) and requirements. A folder can contain both a folder or a requirement while a requirement must be a leaf. Moreover both folder and requirements has a field with the same name.

Now I'm trying to write a VBScript which starting from the change of that field in a father folder, changes the same field in ALL its child AT EVERY nested level. I have problems in propagate the change at nested levels.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Chris Cris
  • 215
  • 3
  • 13
  • This tree is a file structure, a database what is it? Whatever it is you should be able to use [Recursive Technique](https://en.wikibooks.org/wiki/A-level_Computing/AQA/Problem_Solving,_Programming,_Operating_Systems,_Databases_and_Networking/Programming_Concepts/Recursive_Techniques) to create a self referencing function that iterates through the tree structure and performs the requested task. – user692942 Sep 15 '15 at 15:08

1 Answers1

0

Iterate through all nested levels using a recursive function.

Put following code in Requirements module script Workflow and change "RQ_USER_01" for the name of a field you need to propagate.

Sub Req_FieldChange(FieldName)
  On Error Resume Next

  If FieldName = "RQ_USER_01" Then
     Set ReqFact = TDConnection.ReqFactory
     FatherId = Req_Fields.Field("RQ_REQ_ID").Value
     NewValue = Req_Fields.Field("RQ_USER_01").Value
    ChangeChildrenField ReqFact, FatherId, NewValue
  End If

  On Error GoTo 0
End Sub

Sub ChangeChildrenField(ReqFact, FatherId, NewValue)
    Set ReqChildrenList = ReqFact.GetChildrenList(FatherId)
    For Each ReqChild in ReqChildrenList
        ReqChild.Field("RQ_USER_01") = NewValue
        ReqChild.Post()
        ChangeChildrenField ReqFact, ReqChild.ID, NewValue
    Next
End Sub