Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to Retrieve Records or Fetch records Based on Modifiedon Value

Posted on by 1,345

Hi,

 i have to fetch records from custom entity like "Test" based on "modifiedon" date field from Contact entity

there is no relationship between two entities , i get modifiedon from "contact" entity and pass this value to "Test" entity , in test entity i have a custom field called "FromDate" , i couldn't retrieve data from test entity by passing modifiedon value to fromdate

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    format your date to yyyy-MM-dd like this:

    function Financialyear()

    {

       debugger;

       var ModifyDate = Xrm.Page.getAttribute("modifiedon").getValue();

    if(ModifyDate){

    var year = ModifyDate.getFullYear();

    var month;

    var day;

    if(dateFieldValue.getMonth()+1 < 10){

    month = "0" + dateFieldValue.getMonth()+1;

    }

    else{

    month = dateFieldValue.getMonth()+1;

    }

    if(dateFieldValue.getDate() < 10){

    day = "0" + dateFieldValue.getDate();

    }

    else{

    day = dateFieldValue.getDate();

    }

    var dateFormat = year + "-" + month + "-" + day;

    }

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

    "<entity name='new_test'>" +

        "<attribute name='new_testid'/>" +

       " <attribute name='new_name'/>" +

        "<attribute name='createdon'/>" +

         "<attribute name='new_fromdate'/>" +

         "<attribute name='new_todate'/>" +

        "<order attribute='new_name' descending='false'/>" +

       "<filter type='and'>" +

          "<condition attribute='new_fromdate' operator='on-or-after' value='" + dateFormat + "' />" +

        "</filter>" +

      "</entity>" +

    "</fetch>";

           var RevenueRecords = XrmServiceToolkit.Soap.Fetch(FecthXml);

          if (RevenueRecords.length > 0) {

               alert("");

           }

       }

  • Verified answer
    Nausher Sayeed Profile Picture
    Nausher Sayeed 520 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Hi,

    Also take care the UTC conversion. CRM stored datatime as UTC.

  • Verified answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Hi,

    You need to manipulate the 'ModifyDate' field.

    When you use the "Xrm.Page.getAttribute("modifiedon").getValue()" function, it returns you the date in a long string format with the Date & Time,, whereas the FetchXML just needs the date to be in 'YYYY-MM-DD' format. 

    So, do the following before your fetchXML

    var formattedDate=ModifyDate .format("yyyy-mm-dd");

    and use the formattedDate variable in the filter instead of ModifyDate .

  • Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Hi All,

      Thanks for your reply.

    i check with advanced find it work perfectly , below my code

    function Financialyear()
    {
        debugger;
        var ModifyDate = Xrm.Page.getAttribute("modifiedon").getValue();
            var FecthXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
     "<entity name='new_test'>" +
         "<attribute name='new_testid'/>" +
        " <attribute name='new_name'/>" +
         "<attribute name='createdon'/>" +
          "<attribute name='new_fromdate'/>" +
          "<attribute name='new_todate'/>" +
         "<order attribute='new_name' descending='false'/>" +
        "<filter type='and'>" +
           "<condition attribute='new_fromdate' operator='on-or-after' value='" + ModifyDate + "' />" +
         "</filter>" +
       "</entity>" +
     "</fetch>";
            var RevenueRecords = XrmServiceToolkit.Soap.Fetch(FecthXml);
           if (RevenueRecords.length > 0) {
                alert("");
            }

        }


  • Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Hi Iswarya,

    I think we can help you better if you post your code here.

  • Nausher Sayeed Profile Picture
    Nausher Sayeed 520 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Hi,

    As Alok Said check modified date and try to use the same query in advance find.

    Cheers,

  • Suggested answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    Kindly check modified on Date value (what are you getting from Contact) ,is it going to fetch any record for Test entity.You can verify it using Advance Find.

    If everything is ok ,then there must be something wrong with QueryExpression or fetchXML ,whatever you are using.If Possible kindle share query code .

  • Suggested answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Unable to Retrieve Records or Fetch records Based on Modifiedon Value

    It depends on FromDate(whether you are getting proper date) and if you have valid criteria and date ,then there is something wrong with Query Expression or fetch xml query (whatever you are using to fetch record).if possible ,kindly share your query code.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans