Does anyone have a code sample I could pick apart that adds a criterion to a query buffer to search for a document based on a custom attribute value? I have been using aaApi_SQueryCriDataBufferAddCriterion to set up the buffer and for all the other criteria I added, the search works, but after adding the criterion to check if the document's custom attribute JOB_NO has a certain value, I've gotten no where. There is no error returned in adding the criterion, it's just that aaApi_FindItemsToBuffer won't return any items and it should.
const GUID pset_ATTRIBUTE_GENERIC = PSET_ATTRIBUTE_GENERIC;
HAADMSBUFFER hCritBuf = (VOID *)NULL;
wchar_t jn[8]=_T("12025");
if ((hCritBuf = aaApi_SQueryCriDataBufferAddCriterion(hCritBuf, 1, GT_RESTRICTION | VT_SINGLE_VALUE | UT_REGULAR, &pset_ATTRIBUTE_GENERIC, L"JOB_NO", 0, DMS_RELATION_EQUAL, AADMS_ATTRFORM_DATATYPE_STRING, jn)) == NULL)
MessageBox::Show("Error adding criterion");
else
ok = aaApi_FindItemsToBuffer (&searchContext, hCritBuf, &cancel, &items);
Thanks,
Stephanie
I haven't used this method on attributes before, but I think you need to include the environment name (or maybe the environment table name) with the attribute you want to search, so something like L"MyEnv.JOB_NO".
And I don't think there is any harm in declaring the jn variable as LPCWSTR from the beginning to match exactly the way the function is defined in the API.
Please note that I post here on a voluntary basis and am not a Bentley employee.
Thanks for the reply, Jeff. Unfortunately making these 2 changes didn't result in my getting any items back. The function now looks like:
aaApi_SQueryCriDataBufferAddCriterion(hCritBuf, 1, GT_RESTRICTION | VT_SINGLE_VALUE | UT_REGULAR, &pset_ATTRIBUTE_GENERIC, L"MDOTMainEnv.JOB_NO", 0, DMS_RELATION_EQUAL, AADMS_ATTRFORM_DATATYPE_STRING, jn)
Any other suggestions?
Stephanie, we'll need a bit more of a complete description here. Can you provide a complete example showing the setup of your search context, etc ? This is important, as the search context does control what attribute columns are selected.
Stephanie, there is nothing apparently wrong in the code snipped you provided. Please only check the column type, and verify it is of a character type; if not - use an integer type (AADMS_ATTRFORM_DATATYPE_INT) for criterion.
As findItems succeeds in your case, there must be an actual SQL executed on database when it runs, and you should be able to see it is the server logs, once you enable logging for "pwise.database". Please inspect the statement and try executing it directly on your database. This may hint towards the problem.
I hope this helps.
Hi Audrius,
While the function to add the criterion to the existing buffer doesn't error, apparently the aaApi_FindItemsToBuffer function returns false, with an error id of 20224. I checked the column type and it is character. The "message" form for that error wasn't informative. Does this id indicate something more helpful?