Written by

Integration Architect at Itzos B.V.
Question Joost Platenburg · Jul 20, 2022

Can I create an User Account from code

LS, Is it possible to create User Accounts, and assign specific Roles to them, from objectscript?

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT [Health:3.3.0]

Comments

Nick Hershberger · Jul 20, 2022

You can use the Create method of the Security.Users class to do that. Bear in mind that class is in %SYS. Documentation for Create is here: Security.Users.

set$nameSpace = "%SYS"if '##class(Security.Users).Exists("testuser") {
    // Set propertiesset props("Enabled")=1set props("Name")=testuser
    set props("FullName")="Test User"set props("SuperUser")=0set props("NameSpace")="USER"set props("Roles")="%Developer,%Operator,TestRole"set props("Password")=userpassword
    set props("PasswordNeverExpires")=0set props("ChangePassword")=0set props("Routine")=""set props("ExpirationDate")=""set props("Flags")=1set props("EmailAddress")=""set status=##class(Security.Users).Create(user, .props)
    if$$$ISERR(status) {
        do$system.Status.DecomposeStatus(status, .err)
    }
}
0