Skip to main content
16-Pearl
November 7, 2023
Solved

When distinct API used for a column, other columns data of infotable also should present in output

  • November 7, 2023
  • 1 reply
  • 1974 views

I have 5 columns in infotable. When Distinct API used for first two columns together, the output infotable should have 5 columns with the distinct values of first 2 columns. How to do this

Best answer by Velkumar

Hi @AP_10343008 

 

It won't take much time. Because you already pulled 4000 rows of data from Windchill and filtered distinct values out of it. 

 

The script will reuse the initially pulled data from the Windchill System it won't make any new calls to Windchill system

 

/VR

1 reply

19-Tanzanite
November 7, 2023

Hi @AP_10343008 

 

You can create query based on your distinct value and merge infotable into single table to get all columns value with distinct value of column1 & column2

// result: INFOTABLE 
let data = me.dummyData();


let params = {
 t: data /* INFOTABLE */ ,
 columns: "Column1,Column2" /* STRING */
};

// result: INFOTABLE
let distinctValue = Resources["InfoTableFunctions"].Distinct(params);

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE()
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "testShape"
});

for (var i = 0; i < distinctValue.length; i++) {
 // Provide your filter using the format as described in the help topic "Query Parameter for Query Services"
 let query = {
 "filters": {
 "type": "And",
 "filters": [{
 "fieldName": "Column1",
 "type": "EQ",
 "value": distinctValue.rows[i].Column1
 },
 {
 "fieldName": "Column2",
 "type": "EQ",
 "value": distinctValue.rows[i].Column2
 }
 ]
 }
 };

 let params = {
 t: data /* INFOTABLE */ ,
 query: query /* QUERY */
 };

 // result: INFOTABLE
 let tempData = Resources["InfoTableFunctions"].Query(params);

 let params2 = {
 t1: result /* INFOTABLE */ ,
 t2: tempData /* INFOTABLE */
 };

 // result: INFOTABLE
 result = Resources["InfoTableFunctions"].Union(params2);

}

 

/VR

16-Pearl
November 7, 2023

As I have fetched 4000 data from windchill, it will take more time to use for loop. So any ither time saving way is there to get all column data by making 2 columns distinct.

Velkumar19-TanzaniteAnswer
19-Tanzanite
November 8, 2023

Hi @AP_10343008 

 

It won't take much time. Because you already pulled 4000 rows of data from Windchill and filtered distinct values out of it. 

 

The script will reuse the initially pulled data from the Windchill System it won't make any new calls to Windchill system

 

/VR