Custom Component - get field's picklist entries in builder?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'm building a custom component, and would like to have a picklist property in the builder that contains the picklist entries for a predefined field.

What's the best way to access a specific field's metadata in the builder? Do I have to create a dynamic model builder-side just to access that?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hey Matt -

Haven't checked to see if this would work but it should.  There might even be a better way but hopefully this gets you what you need.

From your builder.js, you can get a model using the following:

skuid.builder.core.getModelFromModelName('MyModel')

From there, you should be able to navigate the fields, etc. to get the picklist values.
(Edited)
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Matt -

Sorry for the false hope but the above actually won't work as it returns the model xmlDefinition, not the actual model.

You can obtain the "field" for the model using the following:

skuid.builder.getFieldInfoFromCache('MyModel', 'MyField')

Unfortunately, that won't get you what you need :(  It appears that under the covers, Skuid is not retrieving picklist entries for model metadata within the builder.  Makes sense, since there isn't anywhere that I can think of where they would need that level of information so for performance reasons, it just doesn't request them.

There are some other APIs that could get you the information but in the end, you'll end up having to make a remote call anyway so to simplify, I think you're original idea of just creating a model and querying will be the easiest approach.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Barry. Off to create a builder-side dynamic model! :)