Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to filter values in lookup based on URL string

(0) ShareShare
ReportReport
Posted on by 135

I have a CRM portal form that has a lookup field displaying as  drop down values. These drop down values are coming from a custom entity. we have close to 1500 drop down values on the form. I would like to show values based on the URL string. Ex. If url string contains PK then I would like to show only values from the custom entity that has code PK. In this case my custom entity has 261 values that have code PK. Similarly if the URL string contains MS then I want to filter the 1500 drop down values into 275 as my custom entity has 275 records with MS as the code. I have a custom web template to render the form in portal. What is the simplest way to achieve this. I am open to add js or liquid. 

Thanks for suggestions

R89

*This post is locked for comments

  • R89 Profile Picture
    R89 135 on at
    RE: How to filter values in lookup based on URL string

    Thanks for the detailed steps. It worked the way I wanted it. Step 2 I had to put the javascript in Entity form instead of webpage.

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    Dmytro Rutkovskyi 1,835 on at
    RE: How to filter values in lookup based on URL string

    There are no OOB option to do this, but you can manage it with JavaScript only and entity list odata configuration.

    Refer to the complete solution here: arpitmscrmhunt.blogspot.com/.../custom-lookup-filtering-in-adxstudiocrm.html

  • Verified answer
    Inogic Profile Picture
    Inogic 436 on at
    RE: How to filter values in lookup based on URL string

    Hi,

    Please follow the below steps.

    Step 1: On the web template of the webpage we will retrieve the data according to the condition using fetch xml.

     

    WebPage => Page Template => Web Template

     

    {% assign completeurl = request.url %}

    {% assign pathquery = request.path_and_query %}              

    {%assign conditionParameter = request.params.id%}

     

    {% fetchxml fetchquery %}

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

      <entity name="new_testcity">

        <attribute name="new_testcityid" />

        <attribute name="new_name" />

        <attribute name="createdon" />

        <order attribute="new_name" descending="false" />

        <filter type="and">

          <condition attribute="new_name" operator="eq" value="{{ conditionParameter }}" />

        </filter>

      </entity>

    </fetch>

    {% endfetchxml %}

     

    {% if page.adx_entityform %}

        {% entityform id: page.adx_entityform.id %}

      {% endif %}

     

    <div style="display:none;">

    <select id="mycity" >

    {% for item in fetchquery.results.entities%}

      <option value={{item.new_testcityid}}>{{item.new_name}}</option>  

    {% endfor%}

    </select>

    </div>

     

    NOTE : 1) {%assign conditionParameter = request.params.id%} will get the id value from query string.

                   2) Pass the conditionparameter according to your fetchxml.

     

     

    Step 2: On the webpage In the Advanced  tab in the Custom javascript field paste the following code:   

     

    window.onload = function () {

        $('#new_city').children('option:not(:first)').remove();

        $("#mycity > option").each(function() {

        $("#new_city").append('<option value="'+this.value+'">'+this.text+'</option>');

    });

    };

     

    Note: This javascript function removes all the <option> tags from the $('#new_city') outbox of box field i.e. ookup dropdown and replace it with the <option> tag created in step1 liquid code $("#mycity").

    Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,468 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,287 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans