Question
· Feb 17, 2021

How to configure Web Applications from code?

How can I activate and configure web applications by code without going to the management portal?

And how to configure the rights of the web-application also by code without clicking on the form in the management portal?

Product version: IRIS 2020.4
Discussion (3)1
Log in or sign up to continue

ClassMethod CreateApplication() As %Status [ CodeMode = objectgenerator ]
{
Set $ZTrap="Error"
Set sc=$$$OK
Write !,"Creating Mitz API",!
Set Here=$Namespace
Set URL="/mitz"
Set $Namespace="%SYS"
If ##class(Security.Applications).Exists(URL) {
Write "Mitz API already exists",!
Else {
Set Props("Name")=URL
Set Props("NameSpace")=Here
Set Props("Description")="Mitz notificatie API endpoint"
Set Props("AutheEnabled")=64
Set Props("DispatchClass")="LSP.Mitz.API"
Set Props("MatchRoles")=":%All"
Set Props("Type")=2 ; CSP App
Set sc=##class(Security.Applications).Create(URL,.Props)
}
Set $Namespace=Here
Return sc
Error
Set $ZTrap=""
If $Data(Here) Set $Namespace=Here
Return $$$ERROR($$$GeneralError,"ErrorTrap: "_$ZError)
}

I was able to run the following commands on my local HS 2018 %SYS namespace to create an application:

Set tWebAppName = "/csp/healthshare/samples/myapp"
Set tProperties("NameSpace") = "samples"
Set tProperties("CookiePath") = "/csp/healthshare/samples/myapp/"
Set tProperties("MatchRoles") = "%DB_CACHE:%All"
Set tSC = ##class(Security.Applications).Create(tWebAppName, .tProperties)

The above code works to assign the MatchRoles, but don't know if that answers your question.  I'd suggest running the delete command between attempts via: Set tSC = ##class(Security.Applications).Delete(tWebAppName) until you programmatically get exactly what you are looking to create.

If the idea is to deploy the solution somewhere and make the web app created automatically I'd suggest using the ZPM.

ZPM can generate the necessary elements of the working web-app in your machine and put it in the module.xml description.

So the ZPM module will deploy the code and will create a web-app (or apps) on the target machine with proper settings - actually with exactly the settings that work on your development machine.

Here are the article and the video.

HTH