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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to compare lookup value to Guid in Xrm.WebApi.RetrieveMultipleRecords?

(0) ShareShare
ReportReport
Posted on by 355

Hi,

I added my JavaScript function to the form of entity Collection.
I want to retrieve the records of entity Movie related to the current Collection, and I'm doing it by using a fetchXml which will be passed inside a Xrm.WebApi.retrieveMultipleRecords.
I can get the Guid of the target entity this way:

var collectionid = formContext.data.entity.getId();


But how can I compare it to the Guid of the lookup record in Movie, inside the fetchXml? 

The follwoing code throws an error ( A binary operator with incompatible types was detected. Found operand types 'Microsoft.Dynamics.CRM.collection' and 'Edm.Guid' for operator kind 'Equal'.") :

var moviesFetchXml = "";          

Xrm.WebApi.retrieveMultipleRecords("movie", "?moviesFetchXml");



I assume that I cannot use collectionid here:
 

 

... and I should substitute it with some variable which stores the Guid value of the lookup/related entity, but I can I retrieve it with JavaScript?

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to compare lookup value to Guid in Xrm.WebApi.RetrieveMultipleRecords?

    Hello,

    What kind of relationship do you have between movie and collection?

    Can you build the query in advanced find and show it?

    Also your code var collectionid = formContext.data.entity.getId(); returns id with { and } - there is not point to include { and } to your FetchXml query.

    One more thing - you code Xrm.WebApi.retrieveMultipleRecords("movie", "?moviesFetchXml"); will never work. Following can though:

    Xrm.WebApi.retrieveMultipleRecords("movie", "?fetchXml=" + moviesFetchXml);

  • Joel D Profile Picture
    355 on at
    RE: How to compare lookup value to Guid in Xrm.WebApi.RetrieveMultipleRecords?

    Hi, thank you very much for replying.

    I edited my code as in the following, now it works:

    var formContext = executionContext.getFormContext();
    var collectionid = formContext.data.entity.getId();
    
    var fetchXmlMovies = "";
    
    Xrm.WebApi.online.retrieveMultipleRecords("movie", "?fetchXml="   fetchXmlMovies)


    (The relationship between collection and movie is 1:N)

  • CU25111214-0 Profile Picture
    on at
    How to compare lookup value to Guid in Xrm.WebApi.RetrieveMultipleRecords?
    When you need to compare a lookup value to a GUID inside Xrm.WebApi.retrieveMultipleRecords, make sure you extract the Collection lookup field’s ID from the form—usually something like formContext.getAttribute("new_collectionid").getValue()[0].id—and then plug that GUID into your FetchXML condition exactly as the raw string without braces. This lets your Movie entity query correctly match the related Collection record, and it works smoothly as long as the lookup is populated. It’s a clean approach when building dynamic URLs or routing logic, especially if you’re structuring your query flow similar to how you’d handle content paths on a site like vedu, where each item relates back through a unique identifier

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 186 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 104

#3
Pallavi Phade Profile Picture

Pallavi Phade 61

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans