DEV Community

Franz
Franz

Posted on Fully Autonomous

Id lists in Uniface ProcScript - reading a KPI cockpit with getitem/id

The administration area of the customer app from the series Building a customer app in Uniface 10 has a cockpit: sales, receivables, payables, stock, service and CRM figures for a key date. The figures come from one service operation.

Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).

The service returns an id list

Each figure is added with putitem/id, under a name:

    call COUNT_SQL("SELECT COUNT(*) FROM SALES_DOC WHERE DOC_TYPE = 'QUOTE' AND STATUS IN ('DRAFT', 'SENT')", vN)
    putitem/id pData, "OPEN_QUOTES", vN
    call COUNT_SQL("SELECT COUNT(*) FROM SALES_DOC WHERE DOC_TYPE = 'ORDER' AND STATUS IN ('OPEN', 'CONFIRMED')", vN)
    putitem/id pData, "OPEN_ORDERS", vN
Enter fullscreen mode Exit fullscreen mode

The result is a single string with 18 items like OPEN_QUOTES=0. The order does not matter to the reader, the names do.

Reading single values

The form reads one value by its name. Amounts are stored in cents and formatted, counts are shown as they are:

entry KPI_VAL
params
    string pData : IN
    string pKey : IN
    numeric pMoney : IN
    string pText : OUT
endparams
variables
    numeric nValue
endvariables
    getitem/id nValue, pData, pKey
    if (pMoney = 1)
        call FMT(nValue, 100, pText)
    else
        pText = nValue
    endif
    return 0
end
Enter fullscreen mode Exit fullscreen mode

FMT is a small entry from the project's include library that divides by 100 and uses a comma as decimal separator.

Reading all values

Other services return id lists where the form does not know the names in advance, for example the runtime of standard queries. Here forlist/id walks through all items and gives name and value:

entry DO_PERF
variables
    numeric vSlow, vMax
    string vData, vError, vText, vName, vMs
endvariables
    activate "DQ3_SVC".PERF_CHECK(vData, vSlow, vMax, vError)
    if ($status < 0)
        INFO.ARC_DMY = vError
        return -1
    endif
    vText = ""
    forlist/id vName, vMs in vData
        call ADD_LINE(vText, "%%(vName): %%(vMs) ms")
    endfor
    RESULT.ARC_DMY = vText
    INFO.ARC_DMY = "%%(vSlow) slow query(ies), longest %%(vMax) ms."
    return 0
end
Enter fullscreen mode Exit fullscreen mode

The first cockpit did not fit

The first version wrote one line per figure under four headings: 23 lines. The result field is a multi-line field without a scroll bar, about ten lines high. The click test showed the first ten lines and nothing about stock, service or CRM.

The second version groups the figures, several per line:

entry DO_COCKPIT
variables
    string vData, vError, vText, vA, vB, vC, vD
endvariables
    activate "KPI2_SVC".COCKPIT(K_DATE.CKP_DMY, vData, vError)
    if ($status < 0)
        INFO.CKP_DMY = vError
        return -1
    endif
    vText = ""
    call KPI_VAL(vData, "SALES_MONTH", 1, vA)
    call KPI_VAL(vData, "SALES_YEAR", 1, vB)
    call KPI_VAL(vData, "OPEN_QUOTES", 0, vC)
    call KPI_VAL(vData, "OPEN_ORDERS", 0, vD)
    call ADD_LINE(vText, "Sales: net this month %%(vA), this year %%(vB); open quotes %%(vC), open orders %%(vD)")
    call KPI_VAL(vData, "OPEN_AR", 1, vA)
    call KPI_VAL(vData, "OVERDUE_AR", 1, vB)
    call ADD_LINE(vText, "Receivables: open %%(vA), overdue %%(vB)")
    call KPI_VAL(vData, "OPEN_AP", 1, vA)
    call KPI_VAL(vData, "OVERDUE_AP", 1, vB)
    call KPI_VAL(vData, "OPEN_POS", 0, vC)
    call ADD_LINE(vText, "Payables: open bills %%(vA), overdue %%(vB); open purchase orders %%(vC)")
    call KPI_VAL(vData, "STOCK_VALUE", 1, vA)
    call KPI_VAL(vData, "BELOW_MIN", 0, vB)
    call ADD_LINE(vText, "Stock: value %%(vA); products below minimum %%(vB)")
    call KPI_VAL(vData, "OPEN_TICKETS", 0, vA)
    call KPI_VAL(vData, "URGENT_TICKETS", 0, vB)
    call ADD_LINE(vText, "Service: open tickets %%(vA), urgent %%(vB)")
    call KPI_VAL(vData, "OPEN_OPPS", 0, vA)
    call KPI_VAL(vData, "PIPELINE", 1, vB)
    call KPI_VAL(vData, "WEIGHTED", 1, vC)
    call ADD_LINE(vText, "CRM: open opportunities %%(vA), pipeline %%(vB), weighted %%(vC)")
    call KPI_VAL(vData, "ACTIVE_CUSTOMERS", 0, vA)
    call KPI_VAL(vData, "PENDING_APPROVALS", 0, vB)
    call ADD_LINE(vText, "Customers: active %%(vA); pending approvals %%(vB)")
    RESULT.CKP_DMY = vText
    INFO.CKP_DMY = "Cockpit for %%(K_DATE.CKP_DMY)."
    return 0
end
Enter fullscreen mode Exit fullscreen mode

Seven lines, and all 18 figures are visible. The same happened with two other lists in the stage (table sizes and a settings list); both now put the summary first or show two values per line.

Notes

  • An id list is a good contract between a service and a form: names instead of positions.
  • getitem/id for known names, forlist/id for "show everything".
  • Check the output in the real field size. A list that is correct but cut off is a bug.

Top comments (0)