Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
danyal Absent Member.
Absent Member.
2263 views

How to checkout requirement through OTA API in HPQC 10?

Hi,

I am working on a versioning enabled project and want to modify the requirements through OTA API but it gives an error "Failed to post Req", after interrogation i found that this entity is not checked out. How do i checkout Req? Only checkout is available on TEST object through VCS but didn't find any supporting method for REQ.

Danyal
0 Likes
6 Replies
Markus Willinge Absent Member.
Absent Member.

Re: How to checkout requirement through OTA API in HPQC 10?

Hello,

same problem for me! Where is the VCS object for class Req???

(I expect such topics within the OTA doc, but there is nothing / nothing useful about versioning! Too bad!!!)

Markus
0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

Re: How to checkout requirement through OTA API in HPQC 10?

This is discussed in another current thread. VCS is not relevant for Req objects. Try this:

Set myReqVC = req.VC
myReqVC.CheckOut

...

myReqVC.CheckIn
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
0 Likes
Markus Willinge Absent Member.
Absent Member.

Re: How to checkout requirement through OTA API in HPQC 10?

Thank you, but the problem was, that I use C# and here a suitable member/function was not provided / not visible by the Req class itself. Now I solved it on my own:

VersionControl is visible for classes which implement the IVersionedEntity. Knowing this you can cast a Req object to a IVersionedEntity object. Then the member/method is finally visible! In my opinion this is a bug in the API for C#!
Here is the complete solution for anyone who is facing this problem in the future (it's not optimized but complete):

TDConnection tdConnection = null;
//DEBUG
try
{
tdConnection = new TDConnection();
tdConnection.InitConnectionEx("http://191.155.111.44:8080/qcbin");
tdConnection.ConnectProjectEx("TRAINING", "MyProject", "myuser", "mypwd");

ReqFactory myReqFactory = (ReqFactory)tdConnection.ReqFactory;
Req myReq = (Req)myReqFactory.AddItem(DBNull.Value);
myReq.Name = "New Hello33";
myReq.TypeId = "1"; // 0=Business, 1=Folder, 2=Functional, 3=group, 4=testing
myReq.ParentId = 0;
myReq.Post();

VersionControl recVC = (VersionControl)((IVersionedEntity)myReq).VC;
recVC.CheckOut("Changing name");
myReq.Name = "New Hello333";
myReq.Post();
recVC.CheckIn("Changed name");

string myReqID = "" + myReq.ID;

Console.WriteLine("[ModuleID] " + myReqID);
try
{
tdConnection.Logout();
tdConnection.Disconnect();
tdConnection = null;
}
catch
{ }
}
catch (Exception ex)
{
Console.WriteLine("[Error] " + ex);
try
{
tdConnection.Logout();
tdConnection.Disconnect();
tdConnection = null;
}
catch
{ }
}



gurmit kaur Absent Member.
Absent Member.

Re: How to checkout requirement through OTA API in HPQC 10?

Thank you so much ! this fixed a problem I was having since couple of days.
0 Likes
Highlighted
Abirami Prabu
Visitor.

Re: How to checkout requirement through OTA API in HPQC 10?

Hi can you please give the same code for VB  because for us it is not working please

0 Likes
Absent Member.. ZD1 Absent Member..
Absent Member..

Re: How to checkout requirement through OTA API in HPQC 10?

Thanks for the code snippet, it saved my day 🙂

I already had to work with items under version control and one useful thing was to determine if it has already been checked out, before trying a checkout. It can be that the code that does an update, crashes or simply someone did a checkout in another open ALM client. So I wanted to extend this sample code with something like the IsCheckedOut property of the VCS object. Unfortunately the version control logic you described for Requirements, does not support something like that, so I came up with a query in a simple function (use it at your own risk)

 

        public static bool CanCheckoutRequirement(string sID)
        {
            try
            {
                Recordset rs = m_ota.RunQuery("select RQ_VC_CHECKOUT_USER_NAME from REQ where RQ_REQ_ID = " + sID + " AND RQ_VC_STATUS = 'Checked_Out'");
                if (rs != null && rs.RecordCount == 0)
                {
                    return true;
                }
                else
                {
                    string sUser = rs[0] ?? "<unknown>";
                    Logging.LogRed("Cannot update HP requirement " + sID + " - it is checked out / locked by user " + sUser);
                }
            }
            catch (Exception e)
            {
                Logging.LogRed("Unhandled exception: " + e.Message + " \n " + e.StackTrace);
            }
            //we don't know what's up
            return false;
        }

(The RunQuery function takes a string, passes it for execution to a Command object, and returns a Recordset)

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.