This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to get list of all products in a database

I want to get a list of all products in the database using C/C API DTK. Is it possible ?

 

Parents
  • 0

    Hello,

    You can use PcmsQuery for the object type PCMS_PRODUCT to obtain UIDs of all products. Then get details per each UID via PcmsInitUid. For instance:

    // "conId" is obtained via connecting somewhere above PcmsObjStruct obj = { 0 }; obj.objType = PCMS_PRODUCT; int noUids = 0; int *uids = NULL; if (PcmsQuery(conId, &obj, 0, &noUids, &uids) == PCMS_OK && noUids) { for (int i = 0; i < noUids) { if (PcmsInitUid(conId, *uids, PCMS_PRODUCT, &obj) != PCMS_OK) continue; // use "obj" to get details of Product } }

    --

    Regards,
    Alex

    --
    Alex Shevchenko
    Sr Development Manager
    Although I work for OpenText, I am speaking for myself and not for OpenText.
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button.

  • 0 in reply to 

    Hi Alex,

    Thank you for your answer.

    Which parameter that i can use to get PRODUCT_NAME please ?

    Is it obj.objId ?

     

  • 0 in reply to 

    That's correct - obj.objId will be a universal member for object ID (Name) in any type of read object. Though for products that value also matches obj.productId.

    BTW - there is a bug in my earlier example: "PcmsInitUid(conId, *uids,..." should be "PcmsInitUid(conId, uids[i],..." to properly iterate through UIDs

    --
    Alex Shevchenko
    Sr Development Manager
    Although I work for OpenText, I am speaking for myself and not for OpenText.
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button.

  • 0 in reply to 

    I try like you say.

    I get noUids = 373. but obj.productId always empty also for obj.objId.

    As below the code that i used :

    PcmsObjStruct obj = { 0 };
    obj.objType = PCMS_PRODUCT;
    int noUids = 0;
    int *uids = NULL;

    if (PcmsQuery(conId, &obj, 0, &noUids, &uids) == PCMS_OK && noUids)
    {
         for (int i = 0; i < noUids; i )
         {
                  if (PcmsInitUid(conId, uids[i], PCMS_PRODUCT, &obj) != PCMS_OK)
                  {
                     continue;
                  }
                  // use "obj" to get details of Product
                  printf("%s\n",obj.productId);
         }
    }

Reply
  • 0 in reply to 

    I try like you say.

    I get noUids = 373. but obj.productId always empty also for obj.objId.

    As below the code that i used :

    PcmsObjStruct obj = { 0 };
    obj.objType = PCMS_PRODUCT;
    int noUids = 0;
    int *uids = NULL;

    if (PcmsQuery(conId, &obj, 0, &noUids, &uids) == PCMS_OK && noUids)
    {
         for (int i = 0; i < noUids; i )
         {
                  if (PcmsInitUid(conId, uids[i], PCMS_PRODUCT, &obj) != PCMS_OK)
                  {
                     continue;
                  }
                  // use "obj" to get details of Product
                  printf("%s\n",obj.productId);
         }
    }

Children