Copyright Mark Cullen of Evergreen Systems, Inc. HP Connect.It and

advertisement
Copyright Mark Cullen of Evergreen Systems, Inc.
HP Connect.It and HP Asset Manager: Query (aka. LookUp) target records using WHERE clause before
processing source records in 5 simple steps using PifNewQueryFromFmtName function.
PifNewQueryFromFmtName():
Description - This function creates a query on the document type defined beforehand in the list
of documents produced by a resource.
Syntax - Function PifNewQueryFromFmtName(strCntrName As String, strFmtName As String,
strLayer As String) As Long
Input parameters:
strCntrName - This parameter contains the name of the resource (on which the query is
performed).
strFmtName - This parameter contains the identifier of the document type (defined
beforehand as a produced document type).
strLayer - This parameter is used to define a production directive for a produced
document type.
Step 1 – Create dedicated connector: Nobody will state you can’t use your existing target Asset
Manager connector however, not only for better performance (as documented in the programmer’s
reference guide), a dedicated connector is INSTANT recognition the scenario mapping is using this
function and querying the target database. To go along with this instant recognition I prefer to use the
term “LookUp” in the dedicated connector name. This dedicated connector name is the value used in
the strCntrName input parameter.
Step 2 – Create an “unchecked” produced document type: This document will be created in the
dedicated connector (step 1 above) and will be for the table against which the lookup will be performed.
The document type name is the value used in the strFmtName input parameter. If you plan on utilizing
any element values from the lookup record then make sure these elements are in this document (see
Step 3 below). Elements used as part of the WHERE clause do not need to be in this document however
it doesn’t hurt anything. Uncheck the checkmark next to this document type to minimize scenario
processing time; by leaving this checked the scenario will generate a produced document for each
record in the lookup table and this adds to the scenario processing time.
Step 3 – Declare global variable(s): Any lookup element values you plan to utilize in the scenario must
be set to a variable (see Step 2 above). Global variables are declared in root branch additional scripts
attribute (sub-tab). I prefer to prefix my global variables with “g_” for recognition to any declared local
variables. Global variables can be used for any node in the current mapping.
Step 4 – Code the lookup logic: This is the standard logic used to perform the lookup. Nobody will state
this logic cannot be used in other mapping attribute (sub-tab) nodes however best practice is to use the
root branch mapping attribute (sub-tab) along with global variables. The example given in the
programmer’s reference guide can be copied and pasted (reproduced here) else ensure your coding
practice works the same.
Dim hQuery as Long
Dim iRc as Long
hQuery = pifNewQueryFromFmtName("Asset Management", "amEmplDept", "Name like 'A%'")
Dim strValue as String – This is a declared local variable
WHILE (iRc = 0)
iRc = pifQueryNext(hQuery)
IF iRc = 0 THEN
strValue = pifQueryGetStringVal(hQuery, "Name")
piflogInfoMsg strValue – This is optional
END IF
WEND
iRc = pifQueryClose(hQuery)
Step 5 - Map global variable(s): To utilize any lookup values as part of the source records being
processed simply add logic where necessary. This logic is used in node branch mapping attribute (subtab) and can be as simple as “RetVal = global variable”. These global variables can only be used in the
current mapping where they have been declared. Same name global variables cannot be declared/used
in separate mappings under same scenario.
Download