9 - Migrate Roles
Last updated 8/05/2025
In the previous chapters, we created the Member role for members of the Book Club application and imported the users for the application. There are a number of users that have been imported and none of them have a role assigned to them, you have two ways you can assign their role. You can add them individually by logging in as admin, selecting a user record and selecting the Member role in the Role field.

Alternatively, We can migrate our Member role into the Book Club application and assign it to all members by using Five's
Once the Member role is assigned to the members, you can log in with each member by using their user ID on the user record and the password: Demo123!
Navigate to Functions
1. Click Logic in the menu.2. Click Functions in the sub-menu.

Add the MigrateRoles Function
1. Click the Add Item button.2. Type MigrateRoles in the Function ID field.
3. Click in the Code field to open the Code Editor.

4. Copy the code block below and paste it over the template in the Code Editor.
function MigrateRoles(five, context, result) {
const iRoleKey = five.getRoleKey('Member');
const updateResults = five.executeQuery(`UPDATE iUser SET iRoleKey = ? WHERE UserID <> 'admin' AND UserID <> 'public'`, 0, iRoleKey);
if (updateResults.isOk() === false) {
return five.createError(updateResults);
}
return five.success(result, 'Migration completed');
}
5. Click the Save button in the editor app bar.

6. Click the Save button in the form app bar.

Navigate to Processes
1. Click Tasks in the menu.2. Click Processes in the sub-menu.

Add the Migrate Roles Process
The Migrate Roles process needs to be created so the
2. Type Migrate Roles in the Title field.

3. Click the Events tab.

4. Click the lookup icon in the Do Run field and select MigrateRoles.

5. Click the Save button in the form app bar.

Navigate to Menus
1. Click Visual in the menu.2. Click Menus in the sub-menu.

Add the Migrate Roles Menu
We will run the Migrate Roles process manually as it only needs to be ran once, so the Migrate Roles process will need a menu. The function, process, and menu can be deleted after the roles have been migrated.
1. Click the Add Item button.2. Type Migrate Roles in the Caption field.
3. Type 100300 before MigrateRoles in the Menu ID field.
4. Type 100300 in the Menu Order field.
5. Click the lookup icon in the Action field and select MigrateRoles (Process).
6. Click the lookup icon in the Parent Menu field and select 100000AdministrationMenu (AdministrationMenu).

7. Click the Save button in the form app bar.

Run the Book Club Application
Deploy or run the Book Club application so you can run the Migrate Roles process and assign the Member role to the book club members.
1. Either click the Run or the Deploy to Development button in the toolbar.2. Type admin in the Username field.
3. Type your password in the Password field.
4. Click the Sign In button.

5. Click Administration Menu in the menu.
6. Click Migrate Roles in the menu.

7. Click the Run button.

8. Click the OK button.

9. Click Users in the menu.
10. Select a member user in the list.
