Sunday, 5 April 2015

GetValueFromContextOrImage in mscrm

 public static T GetValueFromContextOrImage<T>(Entity contextRecord, string fieldName, Entity image = null)
      {
          if (contextRecord != null && contextRecord.Contains(fieldName))
          {
              return contextRecord.GetAttributeValue<T>(fieldName);
          }
          else if (image != null && image.Contains(fieldName))
          {
              return image.GetAttributeValue<T>(fieldName);
          }

          return new Entity().GetAttributeValue<T>("dummyValue");
      }

///////////////////////////////////////////////////////////////////////////////

 DateTime date = demoexample.GetLocalTime(tracing, service, context, demoexample.GetValueFromContextOrImage<DateTime>(ImportedData, "hrrrrrr_date"));
               string Fdate = string.Format("{0}-{1}-{2}", date.Year, date.Month, date.Day);

No comments:

Post a Comment