简体   繁体   中英

Fetch DateTime CRM 2011

Im having some trouble with DateTime: Using Fetch

  <attribute name='new_startdate' groupby='true' dategrouping='day' alias='new_startdate' /> 
  <attribute name='new_enddate' groupby='true' dategrouping='day' alias='new_enddate' /> 
  <attribute name='new_duedate' groupby='true' dategrouping='day' alias='new_duedate' /> 

Think this is the bit thats Wrong....

  DateTime scheduledstart = ((DateTime)((AliasedValue)a["new_startdate"]).Value);
  tracer.Trace("DateTime 1 Done");
  DateTime enddate = ((DateTime)((AliasedValue)a["new_enddate"]).Value);
  tracer.Trace("DateTime 2 Done");
  DateTime scheduledend = ((DateTime)((AliasedValue)a["new_duedate"]).Value);

Then i add to the new Entity...

    if (scheduledstart != null)
    {
      Activity.Attributes.Add("scheduledstart", scheduledstart);
    }
    if (enddate != null)
    {
       Activity.Attributes.Add("scheduledend", enddate);
    }
    if (scheduledend != null)
    {
     Activity.Attributes.Add("scheduledend", scheduledend);
    }

Any Ideas How i write the DateTime using AliasedValue from fetch? or a better way to do this>

Thanks

I used to hate dealing with aliased values, but then I wrote some extension methods and now I don't worry about them any more. Check out my blog Simplifying Retrieval of Aliased Values in CRM 2011 . I'm thinking it'll help solve your current problem.

Thanks for the help, I have decided to just use a seperate fetch for the date values

string Date_Gather = string.Format(@"         
      <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
         <entity name='new_import'>                       
                 <attribute name='new_enddate'/>         
         </entity>
       </fetch>", entity.Id);

foreach (var b in Date_Gather_result.Entities)
{

   if (b.Attributes.Contains("new_enddate"))
      {
          enddate = ((DateTime)(b["new_enddate"]));
          Entity.Attributes.Add("scheduledend", enddate);
      }
}

Thanks anyway hope it helps others

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM