Unanswered Need to programatically import a query to a new iteration

  • Wednesday, August 11, 2010 5:41 PM
     
     

    I'm using TFS 2010.

    I need to create a tool that will create new iterations and import queries. I've got my code to create the new iteration, and I can see it when I open the "Areas and Iterations" dialog. When I go to create the QueryDefinition, I get the following error.

         TF51011: The node specified is not found in the classification hierarchy. The error is caused by «'$$PROJECTNAME$$\test'

    The query I'm using is one I have saved. Before adding the query, I modify the query text so that it will use the new iteration name. If I modify an already existing query in my team project I can use the new iteration, but not when I try to programatically do it.

    Any ideas?

     

    Thanks,

    Anthony

     

All Replies

  • Thursday, August 12, 2010 4:45 AM
    Moderator
     
     

    Hi Anthony,

    What is the Query? Could you post so that I can test in my environment?


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
  • Thursday, August 12, 2010 12:57 PM
     
      Has Code

    It is actually the Active Bugs query that is part of the MS Agile template.

    Also, here is the code that I am using to do this. Maybe I'm doing something wrong.

    // iName = the name of the new iteration<br/>
    <br/>
    // create iteration
    ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
    ProjectInfo projectInfo = css.GetProjectFromName(teamProject);
    NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);
    string IterationUri = null;
    foreach (NodeInfo node in nodes)
    {
      if (node.Name == "Iteration")
        IterationUri = node.Uri;
    }
    css.CreateNode(iName, IterationUri);
    
    // add queries for new iteration
    QueryFolder queryFolder = new QueryFolder(iName);
    teamQueriesFolder.Add(queryFolder);
    foreach (string queryName in importQueries)
    {
      string queryFile = queryLocation + queryName.Replace(" ", "") + ".wiq";
      string queryText = XDocument.Load(queryFile).Descendants("Wiql").First().Value.ToString();
      queryText = queryText.Replace("Iteration 1", iName);  <br/>
      QueryDefinition query = new QueryDefinition(queryName, queryText, queryFolder);
    
      queries.Save();
    }
    
    

     

    Thanks,

    Anthony

  • Tuesday, November 09, 2010 10:22 PM
     
     

    Try adding the query to your queryFolder before saving.

      QueryDefinition query = new QueryDefinition(queryName, queryText, queryFolder);
      queryFolder.Add(query);
      queries.Save();
    }

  • Wednesday, November 10, 2010 1:31 PM
     
     

    Unfortunately my error is occuring on line above your new one.

     

    It is the "QueryDefinition query = new QueryDefinition(queryName, queryText, queryFolder);" statement that is throwing the error.

     

    Here are the full exception details.

    Microsoft.TeamFoundation.WorkItemTracking.Client.InvalidQueryTextException was unhandled

      Message=TF51011: The node specified is not found in the classification hierarchy. The error is caused by «'MyProject\test'».

      Source=Microsoft.TeamFoundation.WorkItemTracking.Client

      IsRemoteException=false

      ErrorId=0

      LogException=false

      StackTrace:

           at Microsoft.TeamFoundation.WorkItemTracking.Client.StoredQuery.ValidateWiql(WorkItemStore store, String queryText)

           at Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition.SetQueryTextWithValidation(String queryText)

           at Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition..ctor(String name, String queryText, QueryFolder parent)

           at ProjectMaintenance.ProjectMaintenance.UpdateProject_Click(Object sender, EventArgs e) in C:\azed\devtfs\TFSUtilities\TFSPilot\Source\ProjectMaintenance\ProjectMaintenance.cs:line 104

           at System.Windows.Forms.Control.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

           at System.Windows.Forms.Control.WndProc(Message& m)

           at System.Windows.Forms.ButtonBase.WndProc(Message& m)

           at System.Windows.Forms.Button.WndProc(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.Run(Form mainForm)

           at ProjectMaintenance.Program.Main() in C:\azed\devtfs\TFSUtilities\TFSPilot\Source\ProjectMaintenance\Program.cs:line 18

           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           at System.Threading.ThreadHelper.ThreadStart()

      InnerException: Microsoft.TeamFoundation.WorkItemTracking.Client.Wiql.SyntaxException

           Message=TF51011: The node specified is not found in the classification hierarchy.

           Source=Microsoft.TeamFoundation.WorkItemTracking.Client

           Details=TF51011: The node specified is not found in the classification hierarchy. The error is caused by «'MyProject\test'».

           StackTrace:

                at Microsoft.TeamFoundation.WorkItemTracking.Client.WiqlAdapter.VerifyCondition(NodeFieldName left, Node right, Condition op, Node errorNode, LinkQueryMode mode)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.WiqlAdapter.VerifyNode(Node node, NodeTableName tableContext, NodeFieldName fieldContext)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.Wiql.NodeCondition.Bind(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.Wiql.Node.BindChildren(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.Wiql.NodeAndOperator.Bind(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.Wiql.NodeSelect.Bind(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)

                at Microsoft.TeamFoundation.WorkItemTracking.Client.StoredQuery.ValidateWiql(WorkItemStore store, String queryText)

           InnerException: 


    If I look under the Areas and Iterations, the new iteration is there so I'm not sure why I am getting the problem.



    Anthony

  • Wednesday, March 16, 2011 9:19 PM
     
     
    I think you didn't save your QueryFolder to the server so it doesn't exist, so you can't save your query there yet.
  • Tuesday, August 07, 2012 8:21 PM
     
     

    I know this is old, but I'm currently experiencing the same issue.  Anyone have a way to solve it?

  • Tuesday, August 07, 2012 10:45 PM
     
     

    Actually Ive created a VS Add In that basicly lets you create iterations, and copies or edit existing queries.

    You can fidn the TFS Iteration Manager  extension on Visual Studio Gallery http://visualstudiogallery.msdn.microsoft.com/c597fa72-1f09-4d3c-a98a-b190fe5abd68 and a couple of post on it at http://mskold.blogspot.se/search/label/Iteration%20Manage

  • Wednesday, August 08, 2012 11:42 AM
     
     
    Nice plug, but unfortunately this doesn't help me since this piece is just one tree in the forest.  I would prefer the suggestions on getting around this error. I think it has something to do with store not being updated/refreshed after the new iteration or area is being created.
  • Wednesday, August 08, 2012 2:27 PM
     
     

    After some thinking/testing, I've confirmed my suspicions that it does have to do with the workitemstore not being updated/refreshed in a timely manner.  When I put in a delay of 1.5 seconds after creating the new Area/Iteration and before getting the WorkItemStore service, I'm able to update/create new queries to reference the new Area or Iteration. 

    Anybody know of a way to do with this without the delay?

  • Wednesday, August 08, 2012 8:04 PM
     
      Has Code

    If I remeber correctly Id solved it with the following calls before I try to save any Queries.

    QueryHierarchy qh= GetGH();
    qh.Project.Store.RefreshCache();
    qh.Refresh();