web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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. 

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • Ar0x Profile Picture
    225 on at

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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

    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?

  • Kokulan Profile Picture
    18,054 on at

    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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

  • Ar0x Profile Picture
    225 on at

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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
11manish Profile Picture

11manish 121

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans