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

RetrieveMulitpleRecords issue

(0) ShareShare
ReportReport
Posted on by 75

Hi guys,

With RetrieveMulitpleRecords, what exactly we need to use or write for the filter ? I am following this blog : https://carldesouza.com/retrieve-and-retrievemultiple-javascript-using-xrm-webapi/

but feel getting lost and lost. Have tried several way on the filter, by using schema name, entity set name, no name etc, but error after error returning until my head spinning already.

So the last script is like this ->

function retrieveJournal() {
//read lookup value
if (Xrm.Page.getAttribute("jm_serviceorder").getValue() != null && Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id != null)
{
var OrderId = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id;
var OrderNum = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].name;
Xrm.Page.getAttribute("jm_description").setValue(OrderNum);
//pass entity, fields, we can use expand to get related entity fields
var Select = "?$select=jm_journalid";
var Filter = "&$filter=jm_serviceorder/jm_ServiceOrder eq "+ OrderId ;
Xrm.WebApi.retrieveMultipleRecords('jm_expensedetail', Select + Filter ).then(
function success(result) {
if (result != null) {

if (result.jm_journalid != null)
Xrm.Page.getAttribute("jm_journalid").setValue(result.jm_journalid);

}
},
function(error) {
alert(error.message);

}
);
}
}

With that script now, I get this error :pastedimage1632916678971v1.png

The problem, if I'm correct, is the filter string, what exactly I should use in order to satisfy this function ? and the field "jm_serviceorder" is a lookup type, same as the blog that I'm following.

Please help.

Thanks

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    I won't answer your question directly. I will suggest a way to automatically generate your filter for the webApi.

    Personally, I use the fetchXml Builder tool. After building my query using this tool. We have the possibility to generate the odata query associated to the fetchXMl. You can refer to the image below:

    pastedimage1632921536445v1.png

  • MedWong Profile Picture
    75 on at

    Hi Mehdi,

    Okay, it looks like it is another tools comes around. However, I would tried this. So this is my finding :

    pastedimage1632929744445v1.png

    Apart to view Odata 4.0 (WebAPI), I also noticed there is view JavaScript as in the image. But how is it  connect with my script ? I'm still can't see what exactly the "filter" or the whole RetreiveMutlipleRecords function needed.

    For the data in the grid, is correct, btw.

    Please advice.

    Thanks

  • MedWong Profile Picture
    75 on at

    Hello everyone,

    Hope someone can help me to resolved this as I really driving blind here.

    I saw in some blog, they're using FetchXml, so I tried using that instead ,like this :

    function retrieveJournal() {
    //read lookup value
    if (Xrm.Page.getAttribute("jm_serviceorder").getValue() != null && Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id != null)
    {
    var OrderId = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id;
    var OrderNum = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].name;
    Xrm.Page.getAttribute("jm_description").setValue(OrderNum);
    //pass entity, fields, we can use expand to get related entity fields
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' top='1'>" +
    "<entity name='jm_expensedetail'>" +
    " <attribute name='jm_journalid' />" +
    " <order attribute='jm_journalid' descending='false' />" +
    " <filter type='and'>" +
    " <condition attribute='jm_serviceorder' operator='eq' value='" + OrderNum + "'/>" +
    " </filter>" +
    "</entity> " +
    "</fetch>";
    fetchXml = "?fetchXml=" + encodeURIComponent(fetchXml);

    Xrm.WebApi.retrieveMultipleRecords('jm_expensedetail', fetchXml ).then(
    function success(result) {
    if (result != null) {

    if (result.jm_journalid != null)
    Xrm.Page.getAttribute("jm_journalid").setValue(result.jm_journalid);

    }
    },
    function(error) {
    alert(error.message);

    }
    );
    }
    }

    This is also after few round of trial and error, but in my POV now, there is no syntax error nor unbalance quote or tag or something. But still I have error which is another different error :

    pastedimage1632935415368v1.png

    This is actually just 1 condition, while I actually have two condition, which I'm not sure where to put. Hope someone can help me through this.

    Thanks

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    Please refer to the code below. I'm not sure if it will work at first, but it would be a good start to solve the problem. 

    function retrieveJournal() {
        //read lookup value
        if (Xrm.Page.getAttribute("jm_serviceorder").getValue() != null && Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id != null) {
            var OrderId = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].id.replace("{","").replace("}","");
            var OrderNum = Xrm.Page.getAttribute("jm_serviceorder").getValue()[0].name;
            Xrm.Page.getAttribute("jm_description").setValue(OrderNum);
            //pass entity, fields, we can use expand to get related entity fields
            var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' top='1'>" +
                "<entity name='jm_expensedetail'>" +
                " <attribute name='jm_journalid' />" +
                " <order attribute='jm_journalid' descending='false' />" +
                " <filter type='and'>" +
                " <condition attribute='jm_serviceorder' operator='eq' value='" + OrderId + "'/>" +
                " </filter>" +
                "</entity> " +
                "</fetch>";
            fetchXml = "?fetchXml=" + encodeURIComponent(fetchXml);

            Xrm.WebApi.retrieveMultipleRecords('jm_expensedetail'fetchXml).then(
                function success(result) {
                    if (result != null) {

                        if (result.jm_journalid != null)
                            Xrm.Page.getAttribute("jm_journalid").setValue(result.jm_journalid);

                    }
                },
                function (error) {
                    alert(error.message);

                }
            );
        }
    }

  • meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, any news ?

  • Ram Prakash Duraisamy Profile Picture
    2,289 on at

    Hello,

    Please check the logical name jm_serviceorder available in jm_expensedetail

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 163 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 158

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans