I’m looking to add a custom field to an import script. The field is a dropdown.
I stumbled upon this post, which documented how to create the field initially as part of the import process:
It worked and the field is created just fine with the proper dropdown options.
But the code I’m using to import that field value is not working. Here’s what I’m using:
post_create_action: proc do |newuser|
if user["legacy_custom_field"].is_a?(String)
newuser.custom_fields = {"user_field_#{@legacy_field.id}" => user["legacy_custom_field"]}
end
end
The field I’m importing is a string, so the code should be running. However, when I run the import, nothing is imported for that field.
The value of user[“legacy_custom_field”] in this example is identical to the options created for this field, but I’m not validating the imported data against the dropdown options. Do I need to do that, or maybe add the data differently since it’s selecting a dropdown? When I explored the user_custom_fields table, this text appears to be stored as a simple string anyway.
What am I missing? Thanks in advance if anyone is able to assist!
Not sure what’s up with your code. You might have a look at the Ning importer, as it does custom fields. I’d add a puts after the if to see if it’s ever getting fired.
You might need to do a newuser.save!, but I don’t think it should be required.
@pfaffman, so this is weird, have you ever run into issues with newuser.save! disabling other areas of an import script if you use it too early? Does that end something that needs to be reinitiated in order for the rest of the script to work?
I noticed once I added that line, avatars no longer imported, but commenting out that line made avatars come in again just fine. That was literally the only change I made to correct the avatar issue. These are entirely different sections of the script too.
Would this potentially have anything to do with using newuser.save! vs newuser.save without the trailing “!”? When I end multiple blocks of code with newuser.save!, I noticed only the first one actually saves.