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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Filtering is not working for multiselect option set in javascript

(0) ShareShare
ReportReport
Posted on by 125
Hi All,
I am using this fucntion to retreive products based on the value in product market which compares the available market to product market and filter the products.
I am facing two problem;
1. First it is not working for multiselect option set like it is filtering only when a value is selected in product market which is an option set but when I select multiple value -it is giving error as invalid argument in product field.
2. It is written on change of product market field but when I am changeing the field ,it is not triggering again and giving new value of product but blank value is showing.
Can you please help on this 
marketProductFilter: function (executionContext) {
        if (!NAT.Common.IsLoggedInUserFromUSA()) {
            var formContext = executionContext.getFormContext();
            if (formContext.getAttribute("productmarket").getValue() != null) {
                var market = formContext.getAttribute("productmarket").getValue();
                if (market !== null) {
                    var fetchXML = "<filter type='and'>" +
                        "<condition attribute='availablemarkets' operator='contain-values'>" +
                        "<value>" + market + "</value>" +
                        "</condition>" +
                        "</filter>";

                    formContext.getControl("product").addPreSearch(function () {
                        formContext.getControl("product").addCustomFilter(fetchXML);
                    });
                }
            }
        }
    },
I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You will have to dynamically add multiple value tag based on number of item selected in multi select option set field

    <condition attribute="markmpn_multiselecttest" condition="contain-values">

           <value>1</value>

           <value>2</value>

         </condition>

  • Dynamics_User07 Profile Picture
    125 on at

       I am passing it as dynamics value , can you please look below marked in red

    var fetchXML = "<filter type='and'>" +

                           "<condition attribute='availablemarkets' operator='contain-values'>" +

                           "<value>" + market + "</value>" +

                           "</condition>" +

                           "</filter>";

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    But you are only passing single <value> tag. You need to have multiple value tag if more than one option is selected in your field.

    Add for loop and loop through market

    Var finalValues;

    for(i=0;i<market.length;i++)

    {

    finalValues=finalValues+"<value>"+market[i]+"</value>";

    }

    Then use finalValues in your fetch XML.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans