I have been asked by our requirement team to automatically set the Target Release and Cycles for new requirements they create.
So far, I have it set so when you create a Requirement, it gets the Cycle from the "RQ_FATHER_ID" and applies that to the new requirement. I have it so if the Parent does not have a cycle then it will default to the first cycle found in the project.
Works well when creating a new requirement under an existing requirement but If I Create a new requirement, then imediatly create another requirement under that then it can't find the Parent to get the cycle from.
Also, another annoyance is that the parents seem to store the cycle info in a different value than what I can set so I'm only pulling the first cycle that is checked in the parent. Would be great if someone had an idea how to check all the items the parent is using.
This is what I have so far: Please note, I am only using the _MoveTo because when you click on the New Folder button it does not seem to trip the _Req_New sub
Sub Template_Req_New Req_Fields("RQ_TYPE_ID").value = "Business" 'Default every new requirement to Business Req_Fields("RQ_USER_TEMPLATE_03").Value = "New" 'Default every new requirement status to New ParentCycle = Req_Fields.Field("RQ_FATHER_ID").Value 'Does not seem to get updated when making a child of a newly created item msgbox "Looking up Parent ID: " & ParentCycle Req_Fields.Field("RQ_TARGET_RCYC").Value = Template_Req_GetParentCycle(ParentCycle) 'Set the Cycle to whatever the Parent is using End Sub Sub Template_Req_MoveTo 'Needed to add to the MoveTo as there are several ways to add a new requirement "specifically folder types" that circumvent the changing of the requirement type dropdown If Req_Fields.Field("RQ_TYPE_ID").Value = "Folder" Then If Req_Fields.Field("RQ_REQ_COMMENT").Value = "" Then 'If this is empty, then it's New, so format properly Req_Fields.Field("RQ_REQ_COMMENT").Value = FolderTemplate 'Populate the Description Template Req_Fields.Field("RQ_TARGET_RCYC").Value = Template_Req_GetParentCycle(Req_Fields.Field("RQ_FATHER_ID").Value) 'Set the Req Cycle and Release from parent End if Req_Fields("RQ_TARGET_RCYC").IsRequired = True 'Now that everything is populated, force Target Cycle as required Req_Fields("RQ_TARGET_REL").IsRequired = True 'Now that everything is populated, force Target Release as required End If End Sub '---------------------------------------------------------------------------------------------------------------------------------------------------- ' Function used to identify the Cycle that the parent requirement is using. ' FatherID = should be passed as: Req_Fields.Field("RQ_FATHER_ID").Value ' If there are multiple Cycles a parent has checked, this will only pull the first of the cycles ' If the parent does not have a Cycle (top level folder) then it will return the first cycle available in the project '---------------------------------------------------------------------------------------------------------------------------------------------------- Function Template_Req_GetParentCycle(FatherID) '******************************************************************************************************* '*** Problems getting the parent of a newly created item, perhaps I need to do a .commit or some refresh before running this function? '******************************************************************************************************* 'Find this new items Parent and use the same cycle it uses. Set Req = TDConnection.ReqFactory.Item(FatherID) 'Need to pull parent Cycle from database ReqCycle = Req.Field("RQ_TARGET_RCYC_VARCHAR") 'Parent Cycle ID, arrives as ;####;####; 'RCYCprnt = Req.Field("RQ_TARGET_RCYC") NewReqCycl = Mid(ReqCycle, 2, 4) 'Pull out just the first cycle incase there are > 1 msgbox "Parent Cycle ReqCycle = " & ReqCycle 'msgbox "Parent RCYCprnt = " & RCYCprnt 'if NewReqCycl = "" then ' NewReqCycl = RCYCprnt 'End If if NewReqCycl = "" then 'If Unable to find a Parent Cycle, then default to the first cycle in the system Set CycF = TDConnection.CycleFactory 'Connect to the CycleFactory Set CycL = CycF.NewList("") 'Set CycL as the list items for the Cycles For Each CycE in CycL NewReqCycl = CycE.ID 'Pull the very first Cycle we find Exit For 'Exit out of the loop after finding one Next End if Set Req = Nothing 'Release the ReqFactory object to free memory Template_Req_GetParentCycle = NewReqCycl 'Return the new Cycle to the calling sub End Function