Import group via CSV gives error message

Import group via CSV gives error message

by Balazs DaVinci -
Number of replies: 8

Hallo Moodle community,

I would like to import groups via a CSV file within a course. I would like to use only the required field "groupname".
But when I import such a file containing only the "groupname" field, then I receive an error message stating that:
"groupname" is not a valid fieldname.

I have also tried the same file with the fieldnames:
groupname; groupidnumber; description; enrolmentkey
Group1;;;
Group2;;;
Group3;;;

But I still get the same error message.
Does anybody know the reason? Or how to import groups only with the groupname?

Many thanks in advance

Average of ratings: -
In reply to Balazs DaVinci

Re: Import group via CSV gives error message

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Groups can be imported with the user upload csv - correct naming is just group1, group2 for the header and then the name of the group in the row.
In reply to Emma Richardson

Re: Import group via CSV gives error message

by Balazs DaVinci -
Thank you Emma,

yes, creating groups via user bulk upload works. I did already hundreds of them and it was always working and still works.

In this particular case I really would like to use the group import function within a course.

Unfortunately even a simple CSV file (UTF-8) like this:
groupname
Group1
Group2
Group3
does not work.
In reply to Balazs DaVinci

Re: Import group via CSV gives error message

by Randy Thornton -
Picture of Documentation writers
Are you using any punctuation when you only have the groupname? If so, leave the punctuation out entirely.

A file of this format will work, since groupname is the only required field:

groupname
GroupA
GroupB
GroupC
In reply to Randy Thornton

Re: Import group via CSV gives error message

by Balazs DaVinci -
Thanks Randy,

I was only using spaces within the group names.
I have removed them just for a test, but unfortunately it still doesn't work.
Even a simple CSV file (UTF-8) like this:
groupname
Group1
Group2
Group3
does not work.
I have tried it within Moodle version 3.9.4 and 3.9.9+.

Try to do such a simple group import within a course. I am really curious if it is working within your Moodle environment.

I have done already hundreds of user bulk uploads with many many group fields and that works.

But this simple group import within a course doesn't work like written in the Moodle documentation.

I wonder if there is a "trick" with a certain header constellation which Moodle would accept in this case.

Many thanks
In reply to Balazs DaVinci

Re: Import group via CSV gives error message

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
It must be something with your site- I just used your file and it instantly created the three groups...I went to groups, import groups, added your file, clicked submit and it was done...is it possible that you are trying to upload in the wrong area of that your database table has been changed somehow?
In reply to Balazs DaVinci

Re: Import group via CSV gives error message

by Randy Thornton -
Picture of Documentation writers
Ah, this is a bug in 3.9, reported in this Tracker: https://tracker.moodle.org/browse/MDL-72342

I got the same error in 3.9 from your sample flle, but it worked fine in the most recent 3.10 and 3.11. The issue was a bug in reading the encoding format of the upload file with UTF-8 encoding. There was no particular workaround for this mentioned in the tracker.

So, the workaround that did work for me was to change to another encoding:

1) Save the original csv file in ISO-8859-1 (Western Europe) character set, also known as ISO Latin 1 or Western ISO-Latin 1. A good editor should be able to allow you to save the file in different encodings. (See https://www.charset.org/charsets/iso-8859-1). I set the line breaks to Unix (LF).

2) When you upload it into Moodle, for your Encoding, choose ISO-8859-1 instead of the default UTF-8.

Worked fine for me this way in 3.9.

This bug was fixed in 3.10.8 and 3.11.4. So, this bug is probably present not only in 3.9 but in earlier point releases of 3.10 and 3.11 as well.




Attachment screenshot_11383.png
In reply to Randy Thornton

Re: Import group via CSV gives error message

by Balazs DaVinci -
Many thanks Randy,

So the solution will be to upgrade Moodle to 3.10 and 3.11.

I just could not find an editor yet, which let me save the CSV in the ISO-8859-1 format.

Many thanks
Kind Regards
In reply to Balazs DaVinci

Re: Import group via CSV gives error message

by Randy Thornton -
Picture of Documentation writers
On a Mac, I use BBEdit, which has a free version. On Windows, I used to use Notepad++ which lets you change encodings too: https://npp-user-manual.org/docs/preferences/#encoding-menu. However, I believe that the regular Notepad let's you save a file with a new encoding too (it used to: File > Save As > Encoding).

Any encoding other than UTF-8 should work as long as you can choose it on the pull down menu in Moodle when you upload the file. I chose the Western Latin one simply because it is very common.
Average of ratings: Useful (1)