Add a work item to an existing project
Moderator: SourceGear
Add a work item to an existing project
I'm trying to import items from our old work-tracking system (a spreadsheet) into Vault's work items. It seems like this should be easy:
Connect to server
For Each item in spreadsheet
Create new work item
Upload new work item
Next
I'm getting terribly unhelpful 'Null reference exception' errors when I run, though, which aren't giving me any insight into what's actually missing.
[spreadsheet operations elided, for loop elided]
Dim conn As VaultClientNetLib.VaultConnection = New VaultClientNetLib.VaultConnection()
conn.InitService(VaultConnection.AccessLevelType.Client)
conn.InitDragnetService()
conn.Login("http://www.[myserver].com/VaultService", "[username]", "[password]")
Dim item As MantisItem = New MantisItem()
item.ID = nextId ' Value from spreadsheet
iitem.Subject = "Text from spreadsheet"
item.Details = "Text from another column"
item.Custom1 = "Text from a third column"
item.StatusID = StatusVal.Open
item.PriorityID = PriorityVal.Medium
conn.AddItem(item) <-- This line fails with a null reference exception: "Object reference not set to an instance of an object" with stack trace of " at VaultClientNetLib.VaultConnection.AddItem(MantisItem& item)
at ExcelToVaultImporter.frmImporter.btnImport_Click(Object sender, EventArgs e)
in C:\Projects\ExcelToVaultImporter\ExcelToVaultImporter\Importer.vb"
Any idea what I'm doing wrong? The API's lack of documentation is making this harder than it needs to be, and the unexplained mingling of Fortress/Dragnet/Mantis as terms among the various work-item references is not helping. At a bare minimum, it would be very helpful if the API returned an error message indicating whether there was some parameter I'm missing on the MantisItem or something.
Connect to server
For Each item in spreadsheet
Create new work item
Upload new work item
Next
I'm getting terribly unhelpful 'Null reference exception' errors when I run, though, which aren't giving me any insight into what's actually missing.
[spreadsheet operations elided, for loop elided]
Dim conn As VaultClientNetLib.VaultConnection = New VaultClientNetLib.VaultConnection()
conn.InitService(VaultConnection.AccessLevelType.Client)
conn.InitDragnetService()
conn.Login("http://www.[myserver].com/VaultService", "[username]", "[password]")
Dim item As MantisItem = New MantisItem()
item.ID = nextId ' Value from spreadsheet
iitem.Subject = "Text from spreadsheet"
item.Details = "Text from another column"
item.Custom1 = "Text from a third column"
item.StatusID = StatusVal.Open
item.PriorityID = PriorityVal.Medium
conn.AddItem(item) <-- This line fails with a null reference exception: "Object reference not set to an instance of an object" with stack trace of " at VaultClientNetLib.VaultConnection.AddItem(MantisItem& item)
at ExcelToVaultImporter.frmImporter.btnImport_Click(Object sender, EventArgs e)
in C:\Projects\ExcelToVaultImporter\ExcelToVaultImporter\Importer.vb"
Any idea what I'm doing wrong? The API's lack of documentation is making this harder than it needs to be, and the unexplained mingling of Fortress/Dragnet/Mantis as terms among the various work-item references is not helping. At a bare minimum, it would be very helpful if the API returned an error message indicating whether there was some parameter I'm missing on the MantisItem or something.
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
Can you look in the server log under %windir%\temp\sgvaultpro\vaultpro.log and see if an error is logged there?
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support
Re: Add a work item to an existing project
No, there is no error logged. It just has the "# Source Gear Vault Professional" header line and nothing else in the log file.
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
Maybe I'm just not seeing it, but I don't see anywhere in your code where which project to add the item to is listed.
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support
Re: Add a work item to an existing project
That could be it. That raises two further questions:
1. Is there a simple way to get the listing of project IDs?
2. Are there any other data that are required fields for adding a new work item?
1. Is there a simple way to get the listing of project IDs?
2. Are there any other data that are required fields for adding a new work item?
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
To see what could go into adding a work item, check out the example posted here: http://support.sourcegear.com/viewtopic.php?f=31&t=8020. The work item is towards the bottom of the code Shannon posted.
You shouldn't need to use the project ID to add an item, just the project name. In Shannon's example, you will see a line where it's used like so:
You shouldn't need to use the project ID to add an item, just the project name. In Shannon's example, you will see a line where it's used like so:
Code: Select all
newItem.ProjectName = projectName;
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support
Re: Add a work item to an existing project
I believe I found the project listing by tracing through that code. We only have one project to import our old bug list into, so I just need to find the project ID one time, which I can do with this:
Dim projects() As MantisProject = new MantisProject[0]
Connection.ListDragnetProjects(out projects)
That lets me get one piece of required information. Is ProjectID the only piece of required information I was missing? The FortressItemExpanded class doesn't have any indication of which fields are required and which are optional when creating a new item.
Dim projects() As MantisProject = new MantisProject[0]
Connection.ListDragnetProjects(out projects)
That lets me get one piece of required information. Is ProjectID the only piece of required information I was missing? The FortressItemExpanded class doesn't have any indication of which fields are required and which are optional when creating a new item.
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
The parts I think that are required are just project, description, type, and details.
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support
Re: Add a work item to an existing project
Now I have all the pieces I need, but something else is catching me up now. After I run these lines, I still get the NullReferenceException:
When I step into this with the debugger, I can see that after the Login call, Conn.DragnetServiceInstance is still listed as 'Nothing.' The same thing happens if I try using 'ProcessCommandListFortressProjects' from ItemTrackingOperations. Is this a configuration issue with our Vault Pro setup? Is there some parameter that needs to be set on our Vault Pro installation to allow me to access the work items?
Code: Select all
Dim conn As VaultClientNetLib.VaultConnection = New VaultClientNetLib.VaultConnection()
conn.InitService(VaultConnection.AccessLevelType.Client)
conn.InitDragnetService()
conn.Login("http://www{myserver}.com/VaultService", txtUser.Text, txtPass.Text)
Dim projects(0) As MantisProject
conn.ListDragnetProjects(projects)
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
Depending on what you want to do, there may be an easier way to do things.
Have you seen the sample code for "AddFortressItem()" within this thread - http://support.sourcegear.com/viewtopic.php?f=31&t=8020
Also VaultClientIntegrationLib has some wrapper methods which may help. See ItemTrackingOperations.ProcessCommandListFortressProjects() for a way to list all projects.
Have you seen the sample code for "AddFortressItem()" within this thread - http://support.sourcegear.com/viewtopic.php?f=31&t=8020
Also VaultClientIntegrationLib has some wrapper methods which may help. See ItemTrackingOperations.ProcessCommandListFortressProjects() for a way to list all projects.
Jeff Clausius
SourceGear
SourceGear
Re: Add a work item to an existing project
That worked. I wasn't able to use it to preserve existing item IDs, but that's not a showstopper or worth spending further time on. Thanks!
Energizing a culture of budget accountabilitiy!
Re: Add a work item to an existing project
Thanks for the update.
Beth Kieler
SourceGear Technical Support
SourceGear Technical Support