• Resolved josephmarkovich

    (@josephmarkovich)


    If I am creating a custom form for updating purposes and want to have it show a yes/no field, do I use this:

    {% set options = metadata["contact"].Attributes["gendercode"].OptionSet.Options %}
    {% for option in options %}
      <li>{{option.Value}} - {{option.Label.UserLocalizedLabel.Label}}</li>
    {% endfor %}

    Or do I do something else to have it show the “Yes” or “No” in the form field when the form loads?

    Thank you.
    Joe

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author alexacrm

    (@alexacrm)

    @josephmarkovich take a look at boolean column type metadata. It’s an optionset but uses BooleanOptionSetMetadata. See https://docs.microsoft.com/power-apps/developer/data-platform/webapi/reference/booleanoptionsetmetadata?view=dataverse-latest. Instead of Options you’d use TrueOption and FalseOption.

    • This reply was modified 2 years, 4 months ago by alexacrm.
    Thread Starter josephmarkovich

    (@josephmarkovich)

    So am I essentially doing something like this?

    {% set optionfalse = metadata["contact"].Attributes["jcma_showonexpertdirectory"].BooleanOptionSet.FalseOption %}
    
    {% set optiontrue = metadata["contact"].Attributes["jcma_showonexpertdirectory"].BooleanOptionSet.TrueOption %}

    And then to get the data in the form, this?

    <option value=”{{ optionfalse.Value }}”>{{ optionfalse.Label }}</option>

    Or do I need do a for loop like other option sets?

    Thank you.
    Joe

    Plugin Author alexacrm

    (@alexacrm)

    @josephmarkovich not quite. You still need to access OptionSet object:

    {% set optionfalse = metadata["contact"].Attributes["donotemail"].OptionSet.FalseOption %}
    {% set optiontrue = metadata["contact"].Attributes["donotemail"].OptionSet.TrueOption %}
    
    <div>
        <select>
            <option value="{{optionfalse.Value}}">{{optionfalse.Label.UserLocalizedLabel.Label}} ({{optionfalse.Value}})</option>
            <option value="{{optiontrue.Value}}">{{optiontrue.Label.UserLocalizedLabel.Label}} ({{optiontrue.Value}})</option>
        </select>
    </div>

    You can debug object hierarchy (php format) using dump function (enabled when WP_DEBUG is true):

    {{ dump(metadata["contact"].Attributes["donotemail"] }}

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Forms with yes/no fields’ is closed to new replies.