batch assign a system role?

batch assign a system role?

by Przemyslaw Stencel -
Number of replies: 7

Is there any way to batch assign many users to a system-wide role?

Average of ratings: -
In reply to Przemyslaw Stencel

Re: batch assign a system role?

by Chris Clark -

Hi  Przemyslaw,

I don't mean to hijack this thread at all, but I came here to post a very similar question that may end up being relevant to you.

Is it possible to assign system roles during a bulk upload?
(This may not help you Przemyslaw if you are looking to add system roles to existing users but if you wanted to create new users with the role it may end up providing an answer) 

I thought I was onto something with the role1, role2 etc fields you can sue during bulk uploads but they don't appear to do anything at the system level? do they only effect the course level?




In reply to Chris Clark

Re: batch assign a system role?

by Przemyslaw Stencel -

Actually, assigning system roles during bulk upload would work for me, too. I could use bulk upload for existing users to update their account info.

But my observation is similar to yours - bulk upload works only at the course level sad

Let's hope someone will be able to provide a solution... smile

In reply to Przemyslaw Stencel

Re: batch assign a system role?

by Chris Clark -

Hey Przemyslaw,

I have found a  way to programmatically assign users to a  system role,  all you need to do is call role_assign($roleid, $userid, $contextid);
$roleid and $contextid are obtainable by inspecting the form you would use to assign a system role manually or via the database and $userid are obtianable by checking out each user you want in the database or in the list of users on the site.

I don't know how familiar you are with php or if this will suit your needs (I only needed to assign the role to newly created users, so I just have a custom signup page with the context and role ids hardcoded and the userid is generated during that process) but it may be of some use, good luck, ill check back here and help if I can.

Average of ratings: Useful (2)
In reply to Chris Clark

Re: batch assign a system role?

by Kumar Shubham -

Hey Chris,

I want the same thing but in a little different manner. I want to assign a role to a user at the time of user creation. I want to add a filed in add user form where I can assign a role to them. What changes I need to do in order to make that work.

Thanks.

In reply to Chris Clark

Re: batch assign a system role?

by Przemyslaw Stencel -
Thank you, Chris smile I'm not very familiar with php, so I guess I'll just have to ask a programmer to write a script form me. But thank you for your hint - it will make the task easier for the programmer smile
In reply to Przemyslaw Stencel

Re: batch assign a system role?

by J Stringer -

Hi everyone,

I realize that no one has posted to this for a while, but just thought I'd post an alternative solution to coding. What I do is I append a unique code to each users last name using bulk upload so the name becomes something like "xdxdxd lastname". I then go to the Assign System Roles and search for xdxdxd. Once they're added to the system role, I remove the xdxdxd from the name. In the case where the search is to many for the search box to return (I think the max is 100?), I'll add xdxdxd to one batch of users and then a different code to another batch.

To add the code to the names, I simply paste the last names into an excel sheet. I then type the code xdxdxd into the adjacent column. I then copy and paste both columns into a text editor. This results in "Lastname <tab> firstname>". I replace the <tab>s with a single space " " and then copy and paste all of that into a single column in my CSV. To go back to the original names, I do a find and replace.

Anyway, hope this helps for anyone who stumbles across this thread in the future.