QueryExprArrayReturn : function( sBO, sBC, sExpr, aFields) {
// Use : Frame.QueryExprArrayReturn (sBO : string nsme of Business
Object,
// sBC : string nsme of Business Component,
// sExpr : search expression to be applied,
// aFields : array of fields to be returned)
// Returns : string replacing fields and parameters from the lookup BC and/or property set
var aFnd, bFound, iRecord, sField;
var aValues = new Array();
var rePattern = /(?<=\[)[^[]*(?=\])/g;
with (TheApp.GetBusObject(sBO).GetBusComp(sBC)) {
while ((aFnd = rePattern.exec(sExpr)) != null) ActivateField(aFnd[0]);
for (var c=0; c < aFields.length; c++) ActivateField(aFields[c]);
ClearToQuery();
SetViewMode(AllView);
SetSearchExpr(sExpr);
ExecuteQuery(ForwardOnly);
if (FirstRecord()) {
iRecord = 0;
for (var i=0; i < aFields.length; i++) {
aValues[aFields[i]] = new Array();
aValues[aFields[i]][iRecord] = GetFieldValue(aFields[i]);
}
while (NextRecord()) {
iRecord++;
for (var i=0; i < aFields.length; i++) {
aValues[aFields[i]][iRecord] = GetFieldValue(aFields[i]);
}
}
}
return(aValues)
}
What is occurring here is pretty straightforward:
- Instantiate a BC using the passed BO/BC strings
- Activate any fields used in the Search Expression
- Activate the fields needing to be returned
- Query using the passed search expression
- If at least one record is found, create an associtive array of field values where the first index is the field name and the second index is the record number
- Continue populating this array for each record found
Probably the most interesting aspect of this query is the use of a regular expression search of the passed in expression to activate and BC fields present there by identifying them in enclosing square brackets [].
As far as I know you don't need to activate fields in your search expression... at least I never run into such situation. I think that siebel does it on background.
ReplyDeletePuli,
ReplyDeleteIn general you do not. This is just me being overcautious. I have had times in the past when eScript would throw an error because a field I was referencing in a search spec was not active. I do not recall the situation, whether it was a specialized field or what, but it always stuck with me. It is probably safe to skip this step though.
Hi Mik,
ReplyDeleteI have small question can't we write a business service to achive this instead of having written as a prototype on application level. I am not sure how its gonna impact performance but input/output parameters could be handeled using property sets. Correct me if i am wrong
Thanks,
-Rahul-