web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    Inogic Profile Picture
    703 on at

    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!

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    1,835 on at

    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

  • R89 Profile Picture
    135 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans