Numeric badge from external source in users profile

Hi, I have a customer who wants to display a custom badge in users profile.
I have to get the badge value in javascript from an external source, so I will call a function with the username as a parameter and this function will return a value for the badge.

For example something like “User points”

Could you please give me a guidance about the best way to accomplish this?
Thanks in advance! :upside_down_face:

Create a user custom field. You can then push a value into it with the API.

But I think you want to do it in a plugin and pull the data with ruby, not javascript.

Got it, I will add a new field in the database then I could create a script to populate that field. Then I will create a badge selecting this new field

I wasn’t sure if a plugin was needed.

Thank you!

You almost certainly don’t want to do that. You can use a user_custom_field (or maybe that’s what you meant, since it’s sort-of the same thing) or the similarly-named-thing in the user customization on the UX.

Understood. One last question, I searched sql queries for granting badges, and I couldn’t find an example who display a user_custom_field in the UI. They just look into the user_custom_field to grant the badge

For example in the screenshot I attached before, The number 105.230 should be stored in the user_custom_field and I need to display it in the badge

Do you know if this is possible?

Thank you and sorry for this dumb questions

I’d have to look at the code to give you real answers.

What you want to do is have your plugin add that custom field to the serializer. You can search some existing plugins for add_to_serializer in plugin.rb for some examples. Then you can wrangle that into the badge on the front end.

1 Like