• Resolved spartaleen

    (@spartaleen)


    How can I set the default value of a lookup based on a value from the querystring url?

    <p><select class=”orderform_col” name=”cr466_interestedinparcel”>{% for recordId, record in entityview.rows %}<option value='{“LogicalName”:”cr466_parcel”, “Id”:”{{recordId}}”, “DisplayName”:””}’>{{record[“cr466_name”].value}}</option>{% endfor %}<br />
    </select></p>

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

    (@alexacrm)

    Hey @spartaleen

    not sure I understand, what are you passing in the querystring? Record id?

    Also, your code is not a lookup, it’s a dropdown. Do you need to select a value in a dropdown (that you’ve populated in twig)?

    Can you clarify what are you trying to do?

    Thanks

    Thread Starter spartaleen

    (@spartaleen)

    Yes, I am looking to select a value in my dropdown based on the record id passed in the querystring. Is this possible please?

    Plugin Author alexacrm

    (@alexacrm)

    @spartaleen

    sure, just use if block to add selected attribute:

    <p><select class="orderform_col" name="cr466_interestedinparcel">
      {% for recordId, record in entityview.rows %}
      <option value='{"LogicalName":"cr466_parcel", "Id":"{{recordId}}", "DisplayName":""}' {% if recordId == params.id }selected{% endif %}>{{record["cr466_name"].value}}</option>
      {% endfor %}
    </select></p>
    Thread Starter spartaleen

    (@spartaleen)

    Thank you for the input. Works great!

    • This reply was modified 4 years, 10 months ago by spartaleen.
    • This reply was modified 4 years, 10 months ago by spartaleen.
    Plugin Author alexacrm

    (@alexacrm)

    It’s a typo in closing %}

    Note that the template is a standard twig. We only provide objects like record. I think you’ll find Twig documentation useful:https://twig.symfony.com/doc

    <p><select class="orderform_col" name="cr466_interestedinparcel">
      {% for recordId, record in entityview.rows %}
      <option value='{"LogicalName":"cr466_parcel", "Id":"{{recordId}}", "DisplayName":""}' {% if recordId == params.id %}selected{% endif %}>{{record["cr466_name"].value}}</option>
      {% endfor %}
    </select></p>
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Set Lookup default value from querystring parameter’ is closed to new replies.