Import custom fields of user with import_scripts Ruby

image
I’ve created the DrupalID field from user fields and now I want to import data into this

create_users(@users_json) do |u|
      {
#        id: u["uid"],
#        name: u["name"],
#        email: u["mail"],#
#       custom_fields: {
#          '1':u["uid"],
#          'DrupalID':u["uid"]
#        },


        id: 2037,
        name: "Test 7",
        email: "test7@gmail.com",
        custom_fields: {
          '1':'test',
          'DrupalID':"test"
        },

        created_at: Time.zone.at(u["created"].to_i),
      }

Is this a question is an answer? Are you saying that your code works?

Yes code works but not for custom fields
I want to update custom fields also

Search the other importer scripts for “custom_field”. I’m sure there are examples; I’m fairly certain I’ve done it before.

1 Like

Yes I checked but we haven’t any example provided of JSON file and field name (what we needs to use)

Also i try to import with CSV, but I have same case (Example files missing)

Just find any script that imports custom user fields and add that to your script

1 Like

I tried also custom_fields.csv from https://github.com/discourse/discourse/blob/main/script/import_scripts/csv_importer.rb
Field name DrupalID

id,user_field_1,DrupalID,Drupal ID,custom_field_DrupalID,drupalid
23456,John,John,Doe,example,johndoe
23457,Jane,Jane,Smith,example1,janesmith

image

It’s not working, showing field blank

Looks like https://github.com/discourse/discourse/blob/main/script/import_scripts/csv_importer.rb#L69-L78 should work, but you have to define the ENV seen in https://github.com/discourse/discourse/blob/main/script/import_scripts/csv_importer.rb#L11.

1 Like