Add a work item to an existing project

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Add a work item to an existing project

Post by pkeeler » Mon Jun 13, 2011 10:24 am

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.
Energizing a culture of budget accountabilitiy!

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by Beth » Mon Jun 13, 2011 3:03 pm

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

pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Re: Add a work item to an existing project

Post by pkeeler » Tue Jun 14, 2011 8:01 am

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!

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by Beth » Tue Jun 14, 2011 3:57 pm

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

pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Re: Add a work item to an existing project

Post by pkeeler » Tue Jun 14, 2011 4:11 pm

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?
Energizing a culture of budget accountabilitiy!

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by Beth » Wed Jun 15, 2011 2:58 pm

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;
Beth Kieler
SourceGear Technical Support

pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Re: Add a work item to an existing project

Post by pkeeler » Wed Jun 15, 2011 3:23 pm

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.
Energizing a culture of budget accountabilitiy!

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by Beth » Wed Jun 15, 2011 3:52 pm

The parts I think that are required are just project, description, type, and details.
Beth Kieler
SourceGear Technical Support

pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Re: Add a work item to an existing project

Post by pkeeler » Thu Jun 16, 2011 8:21 am

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?
Energizing a culture of budget accountabilitiy!

jclausius
Posts: 3702
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by jclausius » Fri Jun 17, 2011 7:59 am

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.
Jeff Clausius
SourceGear

pkeeler
Posts: 6
Joined: Mon Jun 13, 2011 9:36 am
Contact:

Re: Add a work item to an existing project

Post by pkeeler » Fri Jun 17, 2011 9:15 am

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!

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Add a work item to an existing project

Post by Beth » Tue Jun 21, 2011 3:12 pm

Thanks for the update.
Beth Kieler
SourceGear Technical Support

Post Reply