Hello DOJO
I am trying to get all parameters of a column from a table with c# automation
6400 is the index of the table
6404 is the index of the column whose data interests me
Element[] elems = engine.FindElementsByProtocol("myprotocol", "Production");
for (int i = 0; i < elems.Length; i++)
if (elems[i].IsActive)
{
var cardtable = elems[i].GetTablePrimaryKeys(6400);
for (int j = 1; j <= cardtable.Length; j++)
{
string index = j.ToString();
var VALELMT = index + " " + elems[i].GetParameterByPrimaryKey(6404, index );
}
}
I added index in the begining of line to see if the loop is OK
It works fine, except the fact that the parameters are identical for all lines :
1 ZQYR018_04
2 ZQYR018_04
3 ZQYR018_04
4 ZQYR018_04
5 ZQYR018_04
What do I miss ?
Hi,
- The value present in cardtable is not being used when executing GetParameterByPrimaryKey. This is now calling with fixed keys from 'index': "1", "2", "3",... (the value of 'index' = variable 'j'). Is this the intention? I would assume that somewhere cardtable[j] would be used to execute GetParameterByPrimaryKey. Also note that the for loop starts with int j = 1, that should probably be 0 and run until j<cardtable.Length or an IndexOutOfRange exception would be thrown when looping until j<=cardtable.Length and then trying to access cardtable[j].
- What is also missing from the screenshot is the value of the displaykey. In the background automation scripts are relying on displaykeys, not primary keys. If the displaykey is duplicate then it will not map back to a correct primary key
Thanks for you help Laurens
I made a mistake by supposing that the index was a row position in database like 0 or 1 for the first element and so on
I succeeded by using a for each loop :
var cardtable = elems[i].GetTablePrimaryKeys(6400);
foreach (var sub in cardtable)
{
VALELMT2 = elems[i].GetParameterByPrimaryKey(6402,sub) ;
etc.