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)

what's wrong with this queryexpression?

(0) ShareShare
ReportReport
Posted on by

Hello, I've defined the following QueryExpression:

var qe = new QueryExpression("annotation");
qe.ColumnSet.AddColumns(new string[] { "filename", "documentbody", "modifiedon" });
qe.Criteria.AddCondition("objectid", ConditionOperator.Equal, incident.Id);
qe.Criteria.AddCondition("modifiedon", ConditionOperator.GreaterEqual, lastPSSaveDateTime); //'12/2/2013 8:15:06 PM'
var notes = orgService.RetrieveMultiple(qe).Entities.ToList();

I copied the variable values during debug, and pasted them into a SQL query:

select filename, documentbody, * from annotation
where objectid = '32e64b43-8e5b-e311-ad17-00155d760004'
and modifiedon > '12/2/2013 8:15:06 PM'

The QueryExpression returns 0 rows, although the SQL query returns 2 rows (as expected). Can you see any problems with my QueryExpression above, that would make it return 0 rows, instead of the expected 2 rows?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Demian Rashkovan Profile Picture
    130 on at

    Your c# code looks right. but what are you doing there is not exactly the same Query.

    When you query to annotation view directly (this is unsiported by the way) the modifiedon fied has the value in GMT, and when you query from c# in aplies the time offset of the current user of the CRM connection in yor orgService.

    Please check if there is any time offset that probably affects your query.

    Best regards

  • Verified answer
    Vijay Waghmare Profile Picture
    on at

    There could be below cases, you are no able to retrieve desired query result

    1 As correctly suggested by Demian you need to check is it a local time or UTC time you are comparing to get the result.

    Refer below forum for more details

    social.microsoft.com/.../datetime-in-a-plugin-in-crm-2011-utc-or-local

    2 When you run SQL query directly in SQL Server, data security won’t apply there, hence you might be getting result in SQL.

    You will also need to check if intended results records having permission for user, under which context in executing.

    Thanks,

    Vijay

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