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

LINQ in query expression calling PrevalidationUpdate in CRM 365 online

(0) ShareShare
ReportReport
Posted on by 2,667

Hi All,

I am using below code to get timezone code value from timezone entity which is a lookup in Opportunity


var query = new QueryExpression(OPPORTUNITY.EntityLogicalName);
query.ColumnSet.AddColumns(OPPORTUNITY.timezoneid, OPPORTUNITY.nristarttime, OPPORTUNITY.nriendtime, OPPORTUNITY.OpportunityId);
query.Criteria.AddCondition(OPPORTUNITY.OpportunityId, ConditionOperator.Equal, targetEntity.Id);
var tZ = query.AddLink("new_timezone", "new_timezoneid", "new_timezoneid", JoinOperator.LeftOuter);
tZ.EntityAlias = "tZ";
tZ.Columns.AddColumns("new_timezonecode");
EntityCollection retrieveColl = organizationService.RetrieveMultiple(query);
tracingService.Trace("Line 323 " + retrieveColl.Entities.Count);
if (retrieveColl != null && retrieveColl.Entities.Count > 0)
{
timeZoneCode = retrieveColl.Entities[0].Attributes.Contains("tZ.new_timezonecode") ? ((AliasedValue)retrieveColl.Entities[0].Attributes["tZ.new_timezonecode"]).Value.ToString() : string.Empty;
tracingService.Trace("Line 325 " + timeZoneCode);
GetLeadData(tracingService, ref nriStartDate, ref nriEndDate, ref timezoneID, retrieveColl);
}

Here when timezone is first time empty & we are trying to update this field value then getting retrieveColl count as 1 but Linq is not working means timezone code not getting.Anything doing wrong here?

But it is working if 2nd time i am updating timezone lookup value on opportunity
pastedimage1669374293885v1.png

But in postoperationUpdate its working fine in prevalidation its taking previous value.

Thanks,

Jharana

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    The reason is that Pre-Operation plugin is executed Before the server operation (so writing the data to the SQL) that's why it queries the old and not new data. And that's why the code works in post operation (because the server operation completed already).

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"

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
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans