Hello!

Can you elaborate on your high-level use case:

  1. What data are you storing?
  2. What do you want to calculate?

Any particular reason you  decided to use globals instead of tables/classes? Article on how globals/tables/classes interact.

In general your task can be solved in two mainstream and one additional way:

  1. Store f. Every time a data point is inserted/updated we calculate and store f(datapoint). Advantage: fast querying and savings on CPU cycles as the calculation work is only performed once. Disadvantage: changing f requires recalculation and time, storage.
  2. Calculate f. Every time data point is accessed we calculate f. Advantage: zero costs to change f, we immediately get new results. No storage required. Disadvantage: potentially CPU intensive load.

Additionally if you need to just check a condition (i.e. that f>0) you may not need an f value as by applying functional analysis, you can solve the issue analytically if f is a continuous function.

Open role as an object (note lowercase):

set role = "%db_cachetemp"
set roleObj = ##class(Security.Roles).%OpenId(role)

Create required resource as an object:

set resouceObj = ##class(Security.Resource).%New()
/// set resource

Insert resource into the role and save the role

do roleObj.Resources.Insert(resourceObj)
set sc = roleObj.%Save()

And role has a new resource.

Invoke is the way to go.

ClassMethod CreateWebApp(pVars, pLogLevel, tInstaller) As %Status
{
    Set Namespace=tInstaller.Evaluate("${Namespace}")
    Do tInstaller.PushNS("%SYS")
    Do ##class(Security.System).GetInstallationSecuritySetting(.security)
    If (security="None") {
        Set cspProperties("AutheEnabled") = $$$AutheUnauthenticated
    } Else {
        Set cspProperties("AutheEnabled") = $$$AutheCache // Password
    }
    Set cspProperties("NameSpace") = Namespace
    Set cspProperties("IsNameSpaceDefault") = $$$YES
    Set cspProperties("DispatchClass") = "MDX2JSON.REST"
        Set cspProperties("UseCookies") = $$$YES
    Set tSC = ##class(Security.Applications).Create("/"_Namespace, .cspProperties)
    Do tInstaller.PopNS()
    If $$$ISERR(tSC) Throw ##class(%Installer.Exception).CreateFromStatus(tSC)
    Quit $$$OK
}

And invoke with

<RunInstall Class="MDX2JSON.Installer" Method="CreateWebApp"/>