Adding a Comment after adding an Item via API

If you are having a problem using Dragnet, post a message here.

Moderator: SourceGear

Locked
birdbuster
Posts: 9
Joined: Thu Mar 29, 2007 10:31 am
Location: Kent,WA

Adding a Comment after adding an Item via API

Post by birdbuster » Mon Apr 02, 2007 3:51 pm

My Question is can I use the same MantisItem that I pass into the
AddItem(MantisItem mi) method to pass into the
AddItemComment(MantisItem mi, MantisItemComment mc) method ?

my ret code is set to 1402 after I call
AddItemComment(MantisItem mi, MantisItemComment mc) method.
Can I please get some further assistance is on what exactly this error is?

You can See I create my MantisItem and then call AddItem and then I create my MantisItemComment and call add on it but, its not getting added correctly so I am wondering if it has something todo with MantisItem not being an out parameter for the AddItem function or if I need to add something to my code.

int ret = -1;
Dragnet.MantisItem mi = new Dragnet.MantisItem();
Dragnet.MantisCategory[] mc;
mi.ProjectID = GetProjectID(ddlApplication.SelectedItem.Text);
ret = dragnetService.ListCategories(mi.ProjectID, out mc);
mi.CategoryID = mc[0].ID;
mi.Description = dr["ScrTitle"].ToString();
mi.Details = dr["ScrDescription"].ToString();
mi.PlatformID = 2; //Windows PlatformID = 2
mi.ItemAccessType = DragnetIntegration.Dragnet.AccessType.Private;
mi.TypeID = 2;
mi.PriorityID = Convert.ToInt32(ddlPriorities.Items.FindByText(dr["SeverityName"].ToString()).Value);
mi.Version = dr["ScrVersionFound"].ToString();
mi.ReporterID = GetUserID(dr["ScrSubmitter"].ToString());
mi.AssigneeID = GetUserID(dr["ScrOwner"].ToString());
mi.TimeEstimateID = 1;
ret = dragnetService.AddItem(mi);
if(ret==0)
{
Dragnet.MantisItemComment mc = new DragnetIntegration.Dragnet.MantisItemComment();
mc.Subject = dr["Title"].ToString();
mc.Content = dr["Contents"].ToString() == "" ? " " : dr["Contents"].ToString();
mc.Html = true;
mc.UID = GetUserID(dr["UserName"].ToString());
mc.Posted = DateTime.Now;
dragnetService.AddItemComment(Item, mc);
}

mskrobul
Posts: 490
Joined: Wed Jan 14, 2004 10:22 am
Location: SourceGear
Contact:

Post by mskrobul » Tue Apr 03, 2007 8:56 am

1402 means that the Item ID was not found.

You will need to get the item you just added to pass into the additemcomment() function (because AddItem doesn't take an out or a ref so that information is missing).

Unfortunately, there isn't a very easy way to do this with the api right now (this feature request is already logged, I will add your vote).

The code example in the following tread shows how to get the item ID for the last item added by a certain user. You should be able to do something very similar to get the item you just added.

http://support.sourcegear.com/viewtopic ... ht=additem
Mary Jo Skrobul
SourceGear

birdbuster
Posts: 9
Joined: Thu Mar 29, 2007 10:31 am
Location: Kent,WA

Easy Way

Post by birdbuster » Tue Apr 03, 2007 11:22 am

For me the easy way is to just query dragnet myself and get the max id from the items table and then set the itemid = that After i call additem(mi);

NEW PROBLEM:

One thing I do notice is that the GUI shows me that the Admin was the user who posted this comment and the admin is the person that I use in my Login in C#.
I do set the MantisItemComment.UID = a valid dragnet UserID, but it uses the admin's UserID instead.

I do leave the MantisItemComment.UserLogin null or do not set it.

I would like to be able to set the MantisItemComment.UID = a valid dragnet UserID.


Thanks

Locked