Last X Months does not function correctly in CRM 2011

强颜欢笑 提交于 2019-12-13 16:23:31

问题


I am creating a view and have tried to get the correct search created, but the results are unexpected. Basically I need to find all records that have been created in the last x months. I created my query:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="new_object">
    <attribute name="new_name" />
    <attribute name="new_dateactivated" />
    <attribute name="new_currentstatus" />
    <attribute name="new_contactid" />
    <attribute name="new_accountid" />
    <attribute name="new_referralsource" />
    <order attribute="new_dateactivated" descending="true" />
    <filter type="and">
      <filter type="or">
        <condition attribute="new_dateenrolled" operator="this-month" />
        <condition attribute="new_dateenrolled" operator="last-x-months" value="2" />
      </filter>
      <condition attribute="ownerid" operator="eq" uiname="---" uitype="systemuser" value="---" />
    </filter>
  </entity>
</fetch>

But when I see the results in a chart/advanced find it only shows the results from the previous 60 days. For example if I run the search right now on Dec 23, it will show all the results from Oct 23 to today. I don't want that, I want to see all the results from Oct 1 to today. It seems as if it is running on a sliding scale or using a really simple function "Last X Months = X * 30"

Can I create a custom search criteria or change the way Dynamics runs this "Last X Months" search?


回答1:


I think it takes all the records from today's day X months ago (for today, the 24th of X months ago). But anyway, I think MS would have to add to FetchXml schema to include the first day X months ago, since it doesn't exist now. (Incidentally, the "Last Month" condition accomplishes what you're looking for, but it only does it for the last month, not for any Xth month ago.)

So I don't think it's possible to intercept the logic behind the "Last X Months" condition, as I'm betting it's wrapped in some core assembly somewhere. However, you can intercept the FetchXml passed to a subgrid via jscript or a report via the VB in the report builder. (It may also be possible for charts, but that's uncharted territory for me.)




回答2:


To me, this works as designed, as long as you understand this is the design and that CRM is pedantic about the last two months counting backwards from today's date and time, not the last two complete calendar months.

The best alternative is to use Last X Fiscal Periods instead, with your fiscal settings set to use calendar months. If you don't have any other purpose for Fiscal Periods in CRM (eg you are not actually using it to do financial reporting aligned to something other than a monthly cycle), then treat these settings as purely "Reporting Periods" and use them in whatever way is more convenient.

Fiscal Periods are "buckets" of time and are treated more like a category axis - a date either falls in one period or another, it does not relate to the current day/time you run the query.

If you want the previous two months plus current month to date, don't forget to put in an OR condition with This Fiscal Period as well.

(yes I know this question is very old, it showed up on the right as similar to another question I was answering, and I thought I could help out here for those who come to this same page later)



来源:https://stackoverflow.com/questions/8621727/last-x-months-does-not-function-correctly-in-crm-2011

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!