Trying to add a new item as closed.

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

Moderator: SourceGear

Post Reply
DetroitJ
Posts: 19
Joined: Fri Sep 26, 2008 12:10 pm
Location: Morrisville, NC
Contact:

Trying to add a new item as closed.

Post by DetroitJ » Thu Jan 15, 2009 1:41 pm

I am trying to write an import util to take our work item list and import it into Fortress. I believe that my technique is correct but for some reason even though I have the status marked as "Closed", when I look at it in Fortress it shows as open. I did create a custom status for "Closed".

Here is my code sample...

ServerOperations.client.LoginOptions.URL = textBox1.Text;
ServerOperations.client.LoginOptions.User = textBox2.Text;
ServerOperations.client.LoginOptions.Password = textBox3.Text;
ServerOperations.Login();

foreach (DataRow row in issuelisttempDataSet.Table_1.Rows)
{
FortressItemExpanded fie = new FortressItemExpanded();
fie.ProjectName = "t1";
fie.Description = row[5].ToString();
fie.Details = "Imported from Issue List Doc:\r\n" +
"Issue #:\t " + row[1].ToString() + "\r\n" +
"Date Open:\t " + row[2].ToString() + "\r\n" +
"Fixed In:\t " + row[3].ToString() + "\r\n" +
"Application:\t " + row[4].ToString() + "\r\n" +
"Description:\r\n\t " + row[5].ToString() + "\r\n\r\n" +
"Resolution Notes:\r\n\t " + row[6].ToString() + "\r\n" +
"Build:\t " + row[7].ToString() + "\r\n" +
"Rel Date:\t " + row[8].ToString() + "\r\n";
fie.Status = "Closed";
fie.ItemType = "Bug";
fie.Priority = "Unknown";
fie.TimeEstimate = "Unknown";
fie.Platform = "Windows";
fie.Category = "";
fie.VersionStr = "";
fie.Custom1 = "Import";
fie.Custom2 = row[7].ToString();
fie.throwExceptions = true;
fie.Validate();
try
{
ItemTrackingOperations.ProcessCommandAddFortressItem(fie);
}
catch (Exception ex)
{

}
I would appreciate if anyone had an idea as to why I can't set the status via code.

Also, I don't see a property for marking an item as public or private.

shannon

Re: Trying to add a new item as closed.

Post by shannon » Thu Jan 15, 2009 2:36 pm

Does it throw an exception? I see that you have it set to throw, but you're catching it.

Did you make a new status with a Status Type of Closed or a Value of Closed? It will be expecting the value.

Can you set the status to anything else and have it work? Verified, for example?

I'm not sure what you mean about marking an item public or private.

DetroitJ
Posts: 19
Joined: Fri Sep 26, 2008 12:10 pm
Location: Morrisville, NC
Contact:

Re: Trying to add a new item as closed.

Post by DetroitJ » Thu Jan 15, 2009 2:49 pm

It is not throwing an exception.
I did create the "Closed" status.
I just tried using "Verified" and it got inserrted as "Open"
When editing an item via the web interface, there is a check box at the top of the form for Public; if the work item project allows Public items. I did just notice that the Public option is not available in the Win or VS client. That actually will cause us some grief.

shannon

Re: Trying to add a new item as closed.

Post by shannon » Thu Jan 15, 2009 5:05 pm

The omission of the public checkbox in the gui client and the vs client has been logged for fixing.

An item is always added with a status of open, by design.

I blanked on public vs private, sorry about that.

Just for some extra information, the FortressItemExpanded is just a wrapper around MantisItemExpanded. It was mostly created to deal with the limitations of what types you can pass around Ant and Nant (have to stick to mostly the primitive types). It is easier to use, because you can pass it strings instead of figuring out what value to pass it, so don't let me discourage you from using it. The downside is, it is basic and therefore much less flexible than the MantisItem types.

Here is what I recommend:

<your code here, up to and including fie.Validate>
// convert to a MantisItem and do the initial add
MantisItem mi = fie.getMantisItem();
MantisItem addedMi = ItemTrackingOperations.ProcessCommandAddItem(mi);
// set your status and public/private flag on the new item
addedMi.StatusID = mi.StatusID;
addedMi.ItemAccessType = MantisLib.AccessType.Private; // or Public
ItemTrackingOperations.ProcessCommandModifyFortressItem(addedMi);

Let me know if this doesn't do what you need.

DetroitJ
Posts: 19
Joined: Fri Sep 26, 2008 12:10 pm
Location: Morrisville, NC
Contact:

Re: Trying to add a new item as closed.

Post by DetroitJ » Fri Jan 16, 2009 1:01 pm

Switching to the MantisItem exposed the needed fields. Thank you very much. Is there any documentation on the MantisItem class?

shannon

Re: Trying to add a new item as closed.

Post by shannon » Fri Jan 16, 2009 1:22 pm

Not exactly. You can look at the code in ItemTrackingOperations.cs for some examples of usage (this is in the VaultClientIntegrationLibCode folder included with the api zipfile). There's some basic information here as well: http://support.sourcegear.com/viewtopic.php?t=2568 (only the first section applies to you).

If you have any trouble, just ask here.

DetroitJ
Posts: 19
Joined: Fri Sep 26, 2008 12:10 pm
Location: Morrisville, NC
Contact:

Re: Trying to add a new item as closed.

Post by DetroitJ » Fri Jan 16, 2009 2:09 pm

Thanks again.

Post Reply