Fetch DateTime CRM 2011

旧城冷巷雨未停 提交于 2019-12-08 01:38:11

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/15290780/fetch-datetime-crm-2011

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