Page 1 of 1

Add a work item to an existing project

Posted: Mon Jun 13, 2011 10:24 am
by pkeeler
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.

Re: Add a work item to an existing project

Posted: Mon Jun 13, 2011 3:03 pm
by Beth
Can you look in the server log under %windir%\temp\sgvaultpro\vaultpro.log and see if an error is logged there?

Re: Add a work item to an existing project

Posted: Tue Jun 14, 2011 8:01 am
by pkeeler
No, there is no error logged. It just has the "# Source Gear Vault Professional" header line and nothing else in the log file.

Re: Add a work item to an existing project

Posted: Tue Jun 14, 2011 3:57 pm
by Beth
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.

Re: Add a work item to an existing project

Posted: Tue Jun 14, 2011 4:11 pm
by pkeeler
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?

Re: Add a work item to an existing project

Posted: Wed Jun 15, 2011 2:58 pm
by Beth
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:

Code: Select all

newItem.ProjectName = projectName;

Re: Add a work item to an existing project

Posted: Wed Jun 15, 2011 3:23 pm
by pkeeler
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.

Re: Add a work item to an existing project

Posted: Wed Jun 15, 2011 3:52 pm
by Beth
The parts I think that are required are just project, description, type, and details.

Re: Add a work item to an existing project

Posted: Thu Jun 16, 2011 8:21 am
by pkeeler
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:

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)
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?

Re: Add a work item to an existing project

Posted: Fri Jun 17, 2011 7:59 am
by jclausius
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.

Re: Add a work item to an existing project

Posted: Fri Jun 17, 2011 9:15 am
by pkeeler
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!

Re: Add a work item to an existing project

Posted: Tue Jun 21, 2011 3:12 pm
by Beth
Thanks for the update.