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 :
Microsoft Dynamics CRM (Archived)

Unable to Retrieve Records or Fetch records Based on Modifiedon Value

(0) ShareShare
ReportReport
Posted on by 1,347

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

I have the same question (0)
  • Suggested answer
    Dynamics_Alok Profile Picture
    1,746 on at

    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.

  • Suggested answer
    Dynamics_Alok Profile Picture
    1,746 on at

    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 .

  • Nausher Sayeed Profile Picture
    522 on at

    Hi,

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

    Cheers,

  • Shidin Haridas Profile Picture
    3,497 on at

    Hi Iswarya,

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

  • Iswarya Profile Picture
    1,347 on at

    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("");
            }

        }


  • Verified answer
    Shidin Haridas Profile Picture
    3,497 on at

    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 .

  • Verified answer
    Nausher Sayeed Profile Picture
    522 on at

    Hi,

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

  • Verified answer
    Community Member Profile Picture
    on at

    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("");

           }

       }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans