Returning Item ID after using AddItemExternal on Web Service

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

Moderator: SourceGear

Locked
AGBrown
Posts: 34
Joined: Wed Aug 10, 2005 1:42 pm
Contact:

Returning Item ID after using AddItemExternal on Web Service

Post by AGBrown » Wed Aug 10, 2005 1:58 pm

We have succesfully run tests to elevate our user requests from our own user-tracking system to Dragnet using AddItemExternal in the web service. However, is there a way to return the new item ID once the item has been accepted? Am I missing something blindingly obvious (very likely)?

Would it be easier if we used AddItem instead? Can we then login through the web service, additem, and then get the last item id added? We could easily make it such that the only people who will be elevating the issues to Dragnet will be Dragnet users anyway, so this wouldn't be a problem for us with regard to user licenses.

Alternatively, should we be adapting our own web service to do this, using your dragnet libraries? Is this allowed by the Dragnet license? It would seem a shame to have to do this given that the Dragnet API seems so comprehensive, and this is the only thing I can't work out how to do (I did say it was quite likely I was missing something)!

Regards,

Andy

ZackJones
Posts: 131
Joined: Mon Mar 08, 2004 6:30 am
Location: Warner Robins, GA

Re: Returning Item ID after using AddItemExternal on Web Ser

Post by ZackJones » Thu Aug 11, 2005 4:58 am

AGBrown wrote:We have succesfully run tests to elevate our user requests from our own user-tracking system to Dragnet using AddItemExternal in the web service. However, is there a way to return the new item ID once the item has been accepted? Am I missing something blindingly obvious (very likely)?
Nope. Dragnet returns a 0 if the item was successfully added, any other value represents some sort of error. Like you, I would like to see the number assigned. Perhaps the Dragnet team could change the return values so that any negative number would represent a failure and any positive number would be the ID number for the item just added.

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

Post by mskrobul » Thu Aug 11, 2005 10:30 am

Would it be easier if we used AddItem instead? Can we then login through the web service, additem, and then get the last item id added? We could easily make it such that the only people who will be elevating the issues to Dragnet will be Dragnet users anyway, so this wouldn't be a problem for us with regard to user licenses.
In your case it sounds like you could just login to the webservice then use AddItem. After that you can query for the last item added by the logged in user.

Here is a very basic example (no error checking) for a query for the last item ID logged by a certain user:

Code: Select all

//The Date Search Areas
public const byte Added = 0x01;
public const byte Updated = 0x02;
public const byte Commented = 0x04;

public int GetLastItemID()
{

int ret = -1;
Dragnet.MantisItemQueryFilter qf = new DragnetWebServiceTests.Dragnet.MantisItemQueryFilter();
Dragnet.MantisItemExpanded[] o = null;
qf.ProjectLevelFilterID = 0; //project id shouldn't matter if you just want the last item by a certain user
qf.DateTo = DateTime.Now;

//get the items added in the past minute 
//you can change this whatever timespan you want 
//or leave qf.DateFrom unspecified to return all items the user has logged
qf.DateFrom = DateTime.Now.Subtract(new TimeSpan(0,1,0)); 

qf.DateItemAreas =Added; //to search for more DateItemAreas or them together "Added | Updated"
qf.Reporters = new int[] { 1 }; //ID of the user who reported the issue

//set to true if you want the item details field filled out for the returned items
ret = _dragnetService.QueryItems(qf, false, out o);

//currenlty all queries from the webservice are returned in ascending order 
//so get the last item in the list just encase more than one item is returned 
int last = o[o.Length - 1].ID;

return last;
}
AddItemExternal is to allow outide users to log items without logging in (for cases where users want customers to be able to log bugs but do nothing else). You could also perform the above code after an AddItemExternal (the external user id is 2), but you would need to login to the webservice as someone who has access to the projects to perform the query.

I have logged a request for the web service AddItem and AddItemExternal to indicate the item id after the add.
Mary Jo Skrobul
SourceGear

AGBrown
Posts: 34
Joined: Wed Aug 10, 2005 1:42 pm
Contact:

Thank you

Post by AGBrown » Sat Aug 20, 2005 5:03 am

That looks like it would work. Thanks for logging the request - it would be nice if we could do:

Login
AddItem
GetLastItemIDAddedByMe
Logout

and maybe a similar process for AddItemExternal, though i can see that this would be harder.

Locked