Commander
Commander
2263 views

How to get list of all products in a database

Jump to solution

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

 

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Hello,

I made this VS solution in VS2017 (attached), though also used that for clean test in VS2019. So, steps are:

1) Extract that somewhere on Windows with Dimensions 14.5 client installed.

2) Copy the contents of Dimensions Client (x86) "C:\Program Files (x86)\Micro Focus\Dimensions 14.5\CM\pcms_api" folder into ConsoleApplication1 folder (to have libs and headers at the same folder).

3) Open the solution in VS and switch the configuration to Release and to x86.

4) Build that (comment out "#include "dmdllsupport.h"" line in clientapi.h if you get a build error for that line).

5) Copied built executable (ConsoleApplication1.exe) to "C:\Program Files (x86)\Micro Focus\Dimensions 14.5\CM\prog\ConsoleApplication1.exe" 

6) Executed with the following parameters: ConsoleApplication1.exe user password dmName dbCon srvHostname
Product : $GENERIC
Product : QLARIUS

I also tried with a user who has very limited privileges - still fine.

View solution in original post

0 Likes
15 Replies
Micro Focus Expert
Micro Focus Expert

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

Commander
Commander

Hi Alex,

Thank you for your answer.

Which parameter that i can use to get PRODUCT_NAME please ?

Is it obj.objId ?

 

0 Likes
Micro Focus Expert
Micro Focus Expert

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 🙂

0 Likes
Commander
Commander

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);
     }
}

0 Likes
Commander
Commander

I have a value just for obj.typeName ="PRODUCT" and empty for all rest parameter.

Any idea to solve this problem please ?

 

 

0 Likes
Micro Focus Expert
Micro Focus Expert

Which version of Dimensions CM are you trying with?

Can your current user has no privileges to access those Product(s)?

Can the code be shared to see how API is used?

0 Likes
Commander
Commander

I use Dimensions CM 14.5.

Sure, i have the access to those product(s) by client application. ( See the picture)

You find as attached the full code.

 

0 Likes
Micro Focus Expert
Micro Focus Expert

OK. Let's sync on how we compile and execute that.

VS2015 Update 3 is installed.
I replace main() of "C:\Program Files\Micro Focus\Dimensions 14.5\cm\pcms_api\examples\progs\FetchItems\fetchitems.c" with your main() code [adjusting connection details to my local server].
I invoke from Windows | Start | "VS2015 x64 Native Tools Command Prompt". 
In VS2015 command prompt: "cd C:\Program Files\Micro Focus\Dimensions 14.5\cm\pcms_api\examples\"
Then compile C file for x64 platform there:
       dm_make --no-cm ARCH=WIN64VC2015 PROG=FetchItems TYPE="prog" all

This results in "C:\Program Files\Micro Focus\Dimensions 14.5\cm\pcms_api\examples\WIN64VC2015\FetchItems\fetchitems.exe". Moving that to "C:\Program Files\Micro Focus\Dimensions 14.5\CM\prog\"  and executing: Products IDs are listed as expected.

If the same steps for you result in empty output at the end, please enable Dimensions CM Server SDP traces, execute the program and provide traces to Support case, so we research that further.

I also tries with x86 compilation at client installation - still proper Product listing.

0 Likes
Commander
Commander

Hi Alex,

All my libs files are in X86.

When i turn execution to X64, i have error in my main program that all libs are in X86 and can't be executed to X64.

 

 

0 Likes
Commander
Commander

I think that the only difference between my configuration and your configuration that you use x64 plugins and i use x86 plugins.

I use CVI/LABWINDOWS 2015 to develop interconnection between Dimension CM and C code.

I try to import my main file with all dependency files like (lib and dll) in visual Studio 2019 but always i have empty result.

Please help.

 

0 Likes
Commander
Commander

You find as below example of error that i have it when i execute my program with x64 bits :

Warning LNK4272 library computer type 'x86' conflicts with target computer type 'x64' ConsoleApplication1 C: \ Program Files (x86) \ Micro Focus \ Dimensions 14.5 \ CM \ pcms_api \ pcms_api10m.lib

LNK2019 error unresolved external symbol PcmsInitUid referenced in main function ConsoleApplication1 C: \ Users \ devapp \ source \ repos \ ConsoleApplication1 \ main.obj LNK2019
 
error unresolved external symbol PcmsQuery referenced in main function ConsoleApplication1 C: \ Users \ devapp \ source \ repos \ ConsoleApplication1 \ main.obj
 
Can you send me a project works with x86 please  ?
 
 
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.