web
You’re offline. This is a read only version of the page.
close
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

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,216 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,216 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,216 User Group Leader on at

    Hi, any news ?

  • Ram Prakash Duraisamy Profile Picture
    2,287 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans