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

Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

(0) ShareShare
ReportReport
Posted on by 225

I'm using a Xrm.Utility.lookupObjects(lookupOptions)-function on a incident-form. Everything works fine, but the filter doesn't work. You should only see the hardware of the customer which belongs to the incident. 

I'm new to xml, so can some help me? 

The code is:

var hardware =[];
function addhardware() {
var lookupOptions = {
defaultEntityType: "new_hardware",
entityTypes: ["new_hardware"],
allowMultiSelect: true
};
var incidentcustomer= Xrm.Page.data.entity.getId();
if(Xrm.Internal.isUci()){
lookupOptions.filters = [{
filterXml: "<filter='and'><condition attribute='new_customer' operator='eq' value=' "+incidentcustomer+" ' /></filter>",
entityLogicalName: "new_hardware"
}];
}
else{
lookupOptions.filters = ["%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22new_customer%22%20operator%3D%22eq%22%20value%3D%22"+incidentcustomer+"%22%20%2F%3E%3C%2Ffilter%3E"];
lookupOptions.customFilterTypes = ["new_hardware"];
}
Xrm.Utility.lookupObjects(lookupOptions)
.then(function (result) {
var text;
for (var i = 0; i < result.length; i++) {
hardware[i]= new Object();
hardware[i].id=result[i].id;
hardware[i].name=result[i].name;
hardware[i].entityType="new_hardware"
}
text=hardware[0].name;
for(var i =1; i < hardware.length; i++) {
text = text +", " + hardware[i].name;
}
Xrm.Page.getAttribute("new_list").setValue(text);
})
.fail(function (error) {});

The variable hardware is used for another function. 

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    If any of replies helped you take a minute and click "Yes" under "Did this answer your question?" near reply that helped you.

  • Ar0x Profile Picture
    225 on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    Thank you for the help. I found a solution for my problem.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    I believe you don't have "_new_customer_value" field in CE. Try to use "new_customer" instead.

  • Kokulan Profile Picture
    18,054 on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    The filtering is not working in one of our implementations where we use the lookupObjects.  The similar issue has been reported and the github page seems to suggest the issue has not been fixed yet.

    Have a look at this page : github.com/.../492

  • Ar0x Profile Picture
    225 on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    thank you for the help.

    But unfortunately it still doesn't work. I tried it even with a static Id of an account.

    var account = "bdc26ec2-df14-ea11-a811-000d3a4b2c9e";

    if(Xrm.Internal.isUci()){

    lookupOptions.filters = [{

    filterXml: "<filter='and'><condition attribute='_new_customer_value' operator='eq' value='bdc26ec2-df14-ea11-a811-000d3a4b2c9e'  /></filter>",

    entityLogicalName: "new_hardware"

    }];

    }

    else{

    lookupOptions.filters = ["%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22_new_customer_value%22%20operator%3D%22eq%22%20value%3D%22"+account+"%22%20%2F%3E%3C%2Ffilter%3E"];

    lookupOptions.customFilterTypes = ["new_hardware"];

    "new_customer" is a lookupfield for accounts.

    Do anybody see the mistake?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    So here is the issue - line var incidentcustomer= Xrm.Page.data.entity.getId(); doesn't give you customer's id. It gives you id of the record. To get customer's id you should use something like

    var incidentcustomer= Xrm.Page.getAttribute("customerid").getValue()[0].id;

  • Ar0x Profile Picture
    225 on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    It is form of case. I call it onchange of a field.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Xrm.Utility.lookupObjects(lookupOptions) filter doesn't work

    Hello,

    I'm confused a little - where do you call your code from? Is it form of the case or account?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 89

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans