Hi,

I'm encountering problems with getting defects linked to a Step in Run. Defects linked to Test Set, TSTest, Test, and Run are found as expected. The linked defects can be correctly seen from the UI. Here's the complete test code I've been using, should compile as such with Visual Studio. Function void handleRunSteps(TDAPIOLELib::IRunPtr run) is where I would expect the defects linked to steps to be found.

Any help would be appreciated!

<font class="small">Code:</font><hr /><pre>
#include &lt;iostream&gt;
#include &lt;string&gt;

#import "C:\Program Files\Common Files\Mercury Interactive\Quality Center\OTAClient.dll"

void handleTestSet(TDAPIOLELib::ITDConnectionPtr qc, const std::string&amp; path, const std::string&amp; set);
void handleTestCases(TDAPIOLELib::ITestSetPtr ts);
void handleTestRuns(TDAPIOLELib::ITSTestPtr tsTest);
void handleRunSteps(TDAPIOLELib::IRunPtr run);

void handleDefects(TDAPIOLELib::ILinkablePtr item);

int main(int argc, char* argv[])
{
if (argc != 8)
{
std::cout
&lt;&lt; "DefectTest.exe &lt;server&gt; &lt;domain&gt; &lt;project&gt; &lt;username&gt; &lt;password&gt; &lt;path TO FOLDER&gt; &lt;setname&gt;"
&lt;&lt; std::endl;
return EXIT_FAILURE;
}

std::string qc_server = argv[1];
std::string qc_domain = argv[2];
std::string qc_project = argv[3];
std::string qc_uname = argv[4];
std::string qc_passwd = argv[5];
std::string qc_path = argv[6];
std::string qc_set = argv[7];

// Initialize COM
CoInitialize(NULL);

// Connect
TDAPIOLELib::ITDConnectionPtr qc(__uuidof(TDAPIOLELib::TDConnection));
qc-&gt;InitConnectionEx(qc_server.c_str());
qc-&gt;ConnectProjectEx(qc_domain.c_str(),
qc_project.c_str(),
qc_uname.c_str(),
qc_passwd.c_str());

std::cout &lt;&lt; "Connected." &lt;&lt; std::endl;

// Start
handleTestSet(qc, qc_path, qc_set);

// Disconnect
qc-&gt;DisconnectProject();
qc-&gt;ReleaseConnection();

// Uninitialize COM
CoUninitialize();
}


void handleTestSet(TDAPIOLELib::ITDConnectionPtr qc, const std::string&amp; path, const std::string&amp; set)
{
// Get the folder
TDAPIOLELib::ITestSetTreeManagerPtr tsTreeManager = qc-&gt;GetTestSetTreeManager();
TDAPIOLELib::ITestSetFolderPtr folder = tsTreeManager-&gt;GetNodeByPath(path.c_str());

// Get the given set
TDAPIOLELib::IListPtr sets = folder-&gt;FindTestSets(set.c_str(), VARIANT_FALSE, "");
if (sets-&gt;Count != 1)
{
std::cout &lt;&lt; "Found more than one set" &lt;&lt; std::endl;
return;
}
TDAPIOLELib::ITestSetPtr ts = sets-&gt;GetItem(1);
std::cout &lt;&lt; "Handling test set " &lt;&lt; ts-&gt;Name &lt;&lt; std::endl;

// Start going through test cases
handleTestCases(ts);
}

void handleTestCases(TDAPIOLELib::ITestSetPtr ts)
{
// Check test sets defects. ILinkable interface is implemented by:
// TestSet, TSTest, Test, Run, Step, Req, Bug
TDAPIOLELib::ILinkablePtr linkable = ts;
if (linkable-&gt;GetHasLinkage())
{
std::cout &lt;&lt; "* Test set has defects." &lt;&lt; std::endl;
handleDefects(linkable);
}
else
{
std::cout &lt;&lt; "* Test set has no defects." &lt;&lt; std::endl;
}

// Get test cases
TDAPIOLELib::IBaseFactoryPtr tsTestFactory = ts-&gt;TSTestFactory;
TDAPIOLELib::IListPtr cases = tsTestFactory-&gt;NewList("");
// Go through test cases
for (long i = 1; i &lt;= cases-&gt;Count; i++)
{
TDAPIOLELib::ITSTestPtr tsTest = cases-&gt;GetItem(i);
TDAPIOLELib::ITestPtr test = tsTest-&gt;Test;

std::cout &lt;&lt; "* Handling test case " &lt;&lt; test-&gt;Name &lt;&lt; std::endl;

// Check defects from TSTest ("test instance")
linkable = tsTest;
if (linkable-&gt;GetHasLinkage())
{
std::cout &lt;&lt; " * Test instance has defects." &lt;&lt; std::endl;
handleDefects(linkable);
}
else
{
std::cout &lt;&lt; " * Test instance has no defects." &lt;&lt; std::endl;
}

// Check defects from Test (in plan)
linkable = test;
if (linkable-&gt;GetHasLinkage())
{
std::cout &lt;&lt; " * Test case has defects." &lt;&lt; std::endl;
handleDefects(linkable);
}
else
{
std::cout &lt;&lt; " * Test case has no defects." &lt;&lt; std::endl;
}

// Runs from test instance
handleTestRuns(tsTest);
}
}

void handleTestRuns(TDAPIOLELib::ITSTestPtr tsTest)
{
std::cout &lt;&lt; " * Handling runs" &lt;&lt; std::endl;

// Get the runs
TDAPIOLELib::IRunFactoryPtr runFactory = tsTest-&gt;GetRunFactory();
TDAPIOLELib::IListPtr runs = runFactory-&gt;NewList("");

// Go through
for (long i = 1; i &lt;= runs-&gt;Count; i++)
{
TDAPIOLELib::IRunPtr run = runs-&gt;GetItem(i);
std::cout &lt;&lt; " * " &lt;&lt; run-&gt;Name &lt;&lt; std::endl;

// Runs defects
TDAPIOLELib::ILinkablePtr linkable = run;
if (linkable-&gt;GetHasLinkage())
{
std::cout &lt;&lt; " * Run has defects." &lt;&lt; std::endl;
handleDefects(linkable);
}
else
{
std::cout &lt;&lt; " * Run has no defects." &lt;&lt; std::endl;
}

// Steps
handleRunSteps(run);
}
}

void handleRunSteps(TDAPIOLELib::IRunPtr run)
{
std::cout &lt;&lt; " * Handling runs steps" &lt;&lt; std::endl;

// Get steps
TDAPIOLELib::IBaseFactoryPtr stepFactory = run-&gt;GetStepFactory();
TDAPIOLELib::IListPtr steps = stepFactory-&gt;NewList("");

// Go through
for (long i = 1; i &lt;= steps-&gt;Count; i++)
{
TDAPIOLELib::IStepPtr step = steps-&gt;GetItem(i);
std::cout &lt;&lt; " * " &lt;&lt; step-&gt;Name &lt;&lt; std::endl;

// And defects
TDAPIOLELib::ILinkablePtr linkable = step;
if (linkable-&gt;GetHasLinkage())
{
std::cout &lt;&lt; " * Step has defects." &lt;&lt; std::endl;
handleDefects(linkable);
}
else
{
std::cout &lt;&lt; " * Step has no defects." &lt;&lt; std::endl;
}
}
}

void handleDefects(TDAPIOLELib::ILinkablePtr item)
{
// Link factory gives the defects?
TDAPIOLELib::ILinkFactoryPtr lf = item-&gt;GetBugLinkFactory();
// "FullLinkage: Indicates that NewList returns child entities
// in addition to the current entity." Should this be used or not?
lf-&gt;FullLinkage = VARIANT_TRUE;

// Get the defects and go through
TDAPIOLELib::IListPtr defects = lf-&gt;NewList("");
for (long i = 1; i &lt;= defects-&gt;Count; i++)
{
TDAPIOLELib::ILinkPtr link = defects-&gt;GetItem(i);

// Target or Source entity? According to documentation, Target would be correct:
/*
SourceEntity and TargetEntity are not fixed attributes of an
association. They reflect the point of view of the factory
from which the Link Object is obtained. SourceEntity and
TargetEntity will always be the same two objects for a
given association. However, which is the source and which
the target may change depending on the Link Object.

For example, when an association between a Test and a Bug is viewed
from the Test side, that is, when the Link object is acquired from
the BugLinkFactory of the Test, SourceEntity is the Test and
TargetEntity is the Bug. If a Link object representing the
same association is acquired from the LinkFactory of the Bug,
SourceEntity is the Bug and TargetEntity is the Test.
*/
TDAPIOLELib::IBugPtr bug = link-&gt;GetTargetEntity();
std::cout
&lt;&lt; " * Found a defect:" &lt;&lt; std::endl &lt;&lt; " "
&lt;&lt; _bstr_t(bug-&gt;GetField("BG_BUG_ID")) &lt;&lt; std::endl;
}
}
</pre><hr />