on 05-31-2007 8:36 PM
I have a lookup field "Category" in main table "Products". How to get the value of field "Category"?
Here is my code:
String searchTable= "Products";
String searchField = "ProductName";
String searchValue = "Product_001";
CMFieldInfoArray fields = catalogData.GetFields(searchTable);
ResultSetDefinition rsd = new ResultSetDefinition(searchTable);
for (int i = 0; i < fields.GetCount(); i++)
{
String fieldName = fields.GetCMFieldInfoAt(i).GetCode();
rsd.AddField(fieldName);
}
Search search = new Search(searchTable);
FreeFormTableParameter fftpNames = search.GetParameters().NewFreeFormTableParameter(searchTable);
FreeFormParameterField ffpfName = fftpNames.GetFields().New(searchField);
ffpfName.GetFreeForm().NewString(searchValue, FreeFormParameter.EqualToSearchType);
A2iResultSet result = catalogData.GetResultSet(search, rsd, null, true, 0);
for ( int i = 0; i < result.GetRecordCount(); i++ )
{
for ( int j = 0; j < result.GetFields().GetCount(); j++ )
{
// if this field is lookup field "Category"
if ( result.GetFieldAt(j).IsLookup() )
{
// Get lookup IDs
A2iIntArray lookupIDs = result.GetLookupIDAt(i, j);
// How to get the value of lookup field "Category"?
}
}
}
Thanks.
Forrest
Hello Forrest,
A2iIntArray lookupIDs = result.GetLookupIDAt(i, j);
//at this point you have the ID of the record of the table "Categories"
int recordId = lookupIDs.GetAt(0);
//you need to access to table "Categories" for get the value (you can create a
//new method getRelValueByID)
String category = this.getRealValueByID(id, CategoryTableName, FieldTableName, catalogData).
In method getRElVAlueByID you only have to implement a search like:
private String getRelValueByID(
int tableID,
String tableName,
String fieldName,
CatalogData catalogData)
{
ResultSetDefinition rsd = null;
A2iResultSet resultSet = null;
A2iIntArray ids = null;
A2iFields fields = null;
String fieldValue = "";
try {
Search search = new Search(tableName);
rsd = new ResultSetDefinition(tableName);
...
//Create here the result set definition
...
ids = new A2iIntArray();
ids.Add(tableID);
// Get Data from table
resultSet = catalogData.GetRecordsById(rsd, ids);
if (resultSet != null) {
fieldValue =
resultSet.GetValueAt(0, fieldName).TranslateToString();
}
} catch (Exception e) {
}
return fieldValue ; }
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.