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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to select records using lookup fields for filter using webapi.

(0) ShareShare
ReportReport
Posted on by 71

Hi,

I tried to select contacts where the account lookup id matches. the following API call works if I remove this 'and parentcustomerid eq '0C9A87ED-A4A0-EC11-B3FE-002248AD8D09' 

As soon as i put that line back, it returns an error. How i can add the account lookup field (parentcustomerid ) to the API call.

I am using the following code. 

function getContact( conId,orgId , formContext)
{

var Entity = "contact";
var Select = "?$select=fullname";
var Filter = "&$filter=contactid eq '3D36A874-49F6-EC11-82E5-002248AE4B85' and parentcustomerid eq '0C9A87ED-A4A0-EC11-B3FE-002248AD8D09'";

Xrm.WebApi.retrieveMultipleRecords(Entity, Select + Filter).then(
function success(result) {
if (result != null && result.entities.length > 0) {
formContext.ui.clearFormNotification("contactid");
} else{
formContext.ui.setFormNotification("The organization for the selected contact should be same as the organization of the ROD contact.", "ERROR", "contactid");
}

},
function (error) {
console.log(error.message);
}
);

}

I have the same question (0)
  • Suggested answer
    RodCTE365 Profile Picture
    15 on at

    Hi Sivar, try replace parentcustomerid with _parentcustomerid_value in your filter

    If you have used XrmToolbox before, open FetchXML Builder and build your query.

    Then select the View menu option and click on the 'OData 4.0 (WebAPI)'.

    The correct syntax will show just above the status bar.

    pastedimage1657382480809v1.png

  • Guido Preite Profile Picture
    54,086 Moderator on at

    you can also use my tool Dataverse REST Builder to create the Web API requests

  • Inogic Profile Picture
    748 on at

    Use below Odata query to fetch contact record based on contactid and parentcustomerid.

     

    var Filter ="&$filter=contactid eq '{3D36A874-49F6-EC11-82E5-002248AE4B85}' and _parentcustomerid_value eq '{0C9A87ED-A4A0-EC11-B3FE-002248AD8D09}'".

     

    To filter any look up field based on GUID the syntax is _fieldname_value .

     

    Alternatively you can also use the below fetch XML

     

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

      <entity name="contact">

     

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

        <filter type="and">

          <condition attribute="contactid" operator="eq" uiname="(ContactName)" uitype="contact" value="{3D36A874-49F6-EC11-82E5-002248AE4B85}" />

          <condition attribute="parentcustomerid" operator="eq" uiname="(AccountName)" uitype="account" value="{0C9A87ED-A4A0-EC11-B3FE-002248AD8D09}" />

        </filter>

      </entity>

    </fetch>"

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 182 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans