Question
Semion Makarov · May 17, 2020

How to create workflow users and roles programmatically?

Hi Community!

Do you know how to create workflow users and roles programmatically?
I use Docker for test deploy and I need to set up IRIS Interoperability using the install script.

Maybe do you know how to import/export already existing workflow users and roles?

0
0 655
Discussion (7)2
Log in or sign up to continue

There are multiple ways, just use Create method directly on classes Security.Roles, and Security.Users

do ##class(Security.Roles).Create(Name, Description, Resources, GrantedRoles)
do ##class(Security.Users).Create(UserName, Roles, Password)

Or, you can use %Installer manifest

<Resource
    Name="%accounting_user" 
    Description="Accounting"
    Permission="RW"/>
<Role 
    Name="%DB_USER"
    Description="Database user"
    Resources="MyResource:RW,MyResource1:RWU"
    RolesGranted= />
<User 
    Username="Clerk1"
    PasswordVar="clerk1pw"
    Roles="Dataentry"
    Fullname="Data Entry Clerk"
    Namespace=
    Routine=
    ExpirationDate=
    ChangePassword=
    Enabled=
    Comment=""/>

I've asked about Workflow users and roles. But I can use your answer to improve my script. Thank you!

Hello,

I created a new role in my Installer class. How can I add the new role to Unknown User in Installer class?

Thanks,

Oliver

Set user = "UnknownUser"
Set role = "Services_Role"
Set tSC = ##class(Security.Users).AddRoles(user,role)
 

<Invoke Class="Security.Users" Method="AddRoles" CheckStatus="1" > 
    <Arg Value="UnknownUser"/>
    <Arg Value="Services_Role"/>
</Invoke>
set user = $username
set role = "MyOperation"
set sc = ##class(EnsLib.Workflow.UserDefinition).CreateUser(user)
set sc = ##class(EnsLib.Workflow.RoleDefinition).CreateRole(role)
set sc = ##class(EnsLib.Workflow.RoleDefinition).AddUserToRole(role, user)

Export role/user globals as xml.