Examples in this topic show how you can use the Bugs_LoadByCriteria
operation to get a list of defects that meet the specified condition. The Condition parameter of the operation specifies the condition XML that lists the criteria the desired defects must meet. To learn how to specify the condition, see LoadByCriteria Operations.
You can get items of other types (releases, requirements, and so on) the same way you get defects. To do this, use the appropriate operation. For example, to get a list of releases that meet the specified condition, use the Releases_LoadByCriteria
operation; to get a list of requirements, use the FunctionalSpecs_LoadByCriteria
operation; and so on. For information on operations you can use to get items by condition, see API Reference.
Defects assigned to a specific user
The sample code below shows how to get a list of defects assigned to a specific user:
C#
string login = "[email protected]";
string password = "p@ssword";
int projID = 10372;
// Specify the condition - get only defects assigned to a specific user
string condition =
@"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opEQU'>
<Items Type='tField'>
<Value xsi:type='xsd:string'>AssigneeUserId</Value>
</Items>
<Items Type='tString'>
<Value xsi:type='xsd:string'>24661</Value>
</Items>
</Conditions>";
string sorting = "Title";
int pageSize = 200;
ServiceSoapClient service = new ServiceSoapClient();
try
{
// Prepare AuthenticationData
LoginInfo loginInfo = service.GetLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.AppCode = loginInfo.AppCode;
authData.UserId = loginInfo.UserId;
authData.PassCode = password;
authData.DeptId = loginInfo.DeptId;
authData.ProjId = projID;
Bug[] bugs;
int pageNumber = 1;
do
{
bugs = service.Bugs_LoadByCriteria(authData, condition, sorting, pageSize, pageNumber);
foreach (Bug bug in bugs)
{
Console.WriteLine("{0}: {1}", bug.BugId, bug.Title);
}
pageNumber++;
}
while (bugs.Length == pageSize);
}
catch (FaultException e)
{
MessageFault msgFault = e.CreateMessageFault();
string error = msgFault.GetReaderAtDetailContents().GetAttribute("Text");
Console.WriteLine(error);
}
Java
import java.util.List;
import javax.xml.ws.soap.SOAPFaultException;
String login = "[email protected]";
String password = "p@ssword";
int projID = 10372;
// Specify the condition - get only defects assigned to a specific user
String condition =
"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opEQU'> \n" +
" <Items Type='tField'> \n" +
" <Value xsi:type='xsd:string'>AssigneeUserId</Value> \n" +
" </Items> \n" +
" <Items Type='tString'> \n" +
" <Value xsi:type='xsd:string'>24661</Value> \n" +
" </Items> \n" +
"</Conditions>";
String sorting = "Title";
int pageSize = 200;
ServiceSoap service = new Service().getServiceSoap12();
try {
// Preparing AuthenticationData
LoginInfo loginInfo = service.getLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.setAppCode(loginInfo.getAppCode());
authData.setUserId(loginInfo.getUserId());
authData.setPassCode(password);
authData.setDeptId(loginInfo.getDeptId());
authData.setProjId(projID);
List<Bug> bugs;
int pageNumber = 1;
do {
bugs = service.bugsLoadByCriteria(authData, condition, sorting, pageSize, pageNumber).getBug();
for (Bug bug : bugs) {
System.out.format("%d: %s%n", bug.getBugId(), bug.getTitle());
}
pageNumber++;
} while (bugs.size() == pageSize);
} catch (SOAPFaultException e) {
e.printStackTrace();
}
Defects with a specific word in the title
The sample code below shows how to get a list of defects that have a specific word in their title:
C#
string login = "[email protected]";
string password = "p@ssword";
int projID = 10372;
// Specify the condition - get only defects that have the "component" word in their title
string condition =
@"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opLIKE'>
<Items Type='tField'>
<Value xsi:type='xsd:string'>Title</Value>
</Items>
<Items Type='tString'>
<Value xsi:type='xsd:string'>%component%</Value>
</Items>
</Conditions>";
string sorting = "Title";
int pageSize = 200;
ServiceSoapClient service = new ServiceSoapClient();
try
{
// Prepare AuthenticationData
LoginInfo loginInfo = service.GetLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.AppCode = loginInfo.AppCode;
authData.UserId = loginInfo.UserId;
authData.PassCode = password;
authData.DeptId = loginInfo.DeptId;
authData.ProjId = projID;
Bug[] bugs;
int pageNumber = 1;
do
{
bugs = service.Bugs_LoadByCriteria(authData, condition, sorting, pageSize, pageNumber);
foreach (Bug bug in bugs)
{
Console.WriteLine("{0}: {1}", bug.BugId, bug.Title);
}
pageNumber++;
}
while (bugs.Length == pageSize);
}
catch (FaultException e)
{
MessageFault msgFault = e.CreateMessageFault();
string error = msgFault.GetReaderAtDetailContents().GetAttribute("Text");
Console.WriteLine(error);
}
Java
import java.util.List;
import javax.xml.ws.soap.SOAPFaultException;
String login = "[email protected]";
String password = "p@ssword";
int projID = 10372;
// Specify the condition - get only defects that have the "component" word in their title
String condition =
"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opLIKE'> \n" +
" <Items Type='tField'> \n" +
" <Value xsi:type='xsd:string'>Title</Value> \n" +
" </Items> \n" +
" <Items Type='tString'> \n" +
" <Value xsi:type='xsd:string'>%component%</Value> \n" +
" </Items> \n" +
"</Conditions>";
String sorting = "Title";
int pageSize = 200;
ServiceSoap service = new Service().getServiceSoap12();
try {
// Preparing AuthenticationData
LoginInfo loginInfo = service.getLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.setAppCode(loginInfo.getAppCode());
authData.setUserId(loginInfo.getUserId());
authData.setPassCode(password);
authData.setDeptId(loginInfo.getDeptId());
authData.setProjId(projID);
List<Bug> bugs;
int pageNumber = 1;
do {
bugs = service.bugsLoadByCriteria(authData, condition, sorting, pageSize, pageNumber).getBug();
for (Bug bug : bugs) {
System.out.format("%d: %s%n", bug.getBugId(), bug.getTitle());
}
pageNumber++;
} while (bugs.size() == pageSize);
} catch (SOAPFaultException e) {
e.printStackTrace();
}
Defect modified today
The sample code below shows how to get a list of defects modified during the current day:
C#
string login = "[email protected]";
string password = "p@ssword";
int projID = 10372;
// Get the current date and convert it to the XML format
string currentDate = DateTime.Today.ToString("s");
// Specify the condition - get only defects modified today
string condition =
@"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opGTE'>
<Items Type='tField'>
<Value xsi:type='xsd:string'>DateUpdated</Value>
</Items>
<Items Type='tDate'>
<Value xsi:type='xsd:string'>" + currentDate + @"</Value>
</Items>
</Conditions>";
string sorting = "Title";
int pageSize = 200;
ServiceSoapClient service = new ServiceSoapClient();
try
{
// Prepare AuthenticationData
LoginInfo loginInfo = service.GetLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.AppCode = loginInfo.AppCode;
authData.UserId = loginInfo.UserId;
authData.PassCode = password;
authData.DeptId = loginInfo.DeptId;
authData.ProjId = projID;
Bug[] bugs;
int pageNumber = 1;
do
{
bugs = service.Bugs_LoadByCriteria(authData, condition, sorting, pageSize, pageNumber);
foreach (Bug bug in bugs)
{
Console.WriteLine("{0}: {1}", bug.BugId, bug.Title);
}
pageNumber++;
}
while (bugs.Length == pageSize);
}
catch (FaultException e)
{
MessageFault msgFault = e.CreateMessageFault();
string error = msgFault.GetReaderAtDetailContents().GetAttribute("Text");
Console.WriteLine(error);
}
Java
import java.util.List;
import javax.xml.ws.soap.SOAPFaultException;
String login = "[email protected]";
String password = "p@ssword";
int projID = 10372;
String condition = "";
try
{
// Get the current date and convert it to the XML format
XMLGregorianCalendar currentDate;
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeZone(TimeZone.getTimeZone("GMT"));
currentDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar) ;
currentDate.setHour(0);
currentDate.setMinute(0);
currentDate.setSecond(0);
currentDate.setMillisecond(0);
// Specify the condition - get only defects modified today
condition =
"<Conditions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema' Operation='opGTE'> \n" +
" <Items Type='tField'> \n" +
" <Value xsi:type='xsd:string'>DateUpdated</Value> \n" +
" </Items> \n" +
" <Items Type='tDate'> \n" +
" <Value xsi:type='xsd:string'>" + currentDate + "</Value> \n" +
" </Items> \n" +
"</Conditions>";
}
catch (Exception e)
{
e.printStackTrace();
}
String sorting = "Title";
int pageSize = 200;
ServiceSoap service = new Service().getServiceSoap12();
try {
// Preparing AuthenticationData
LoginInfo loginInfo = service.getLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.setAppCode(loginInfo.getAppCode());
authData.setUserId(loginInfo.getUserId());
authData.setPassCode(password);
authData.setDeptId(loginInfo.getDeptId());
authData.setProjId(projID);
List<Bug> bugs;
int pageNumber = 1;
do {
bugs = service.bugsLoadByCriteria(authData, condition, sorting, pageSize, pageNumber).getBug();
for (Bug bug : bugs) {
System.out.format("%d: %s%n", bug.getBugId(), bug.getTitle());
}
pageNumber++;
} while (bugs.size() == pageSize);
} catch (SOAPFaultException e) {
e.printStackTrace();
}