public void PopulateField(string field, Entity entity) { var type = entity.LogicalName; var fieldType = XrmService.GetFieldType(field, type); switch (fieldType) { case AttributeTypeCode.BigInt: { entity.SetField(field, 1); break; } case AttributeTypeCode.Boolean: { entity.SetField(field, true); break; } case AttributeTypeCode.CalendarRules: { break; } case AttributeTypeCode.Customer: { entity.SetField(field, CreateAccount()); break; } case AttributeTypeCode.DateTime: { var now = DateTime.UtcNow; var noMilliSeconds = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, DateTimeKind.Utc); entity.SetField(field, noMilliSeconds); break; } case AttributeTypeCode.Decimal: { entity.SetField(field, (decimal)1); break; } case AttributeTypeCode.Double: { entity.SetField(field, (double)1); break; } case AttributeTypeCode.EntityName: { break; } case AttributeTypeCode.Integer: { entity.SetField(field, 1); break; } case AttributeTypeCode.Lookup: { var target = XrmService.GetLookupTargetEntity(field, type); var typesToExlcude = new[] { "equipment", "transactioncurrency", "pricelevel", "service", "systemuser", "incident", "campaign", "territory" }; if (!typesToExlcude.Contains(target)) { entity.SetField(field, CreateTestRecord(target).ToEntityReference()); } break; } case AttributeTypeCode.ManagedProperty: { break; } case AttributeTypeCode.Memo: { entity.SetField(field, "blah blah blah \n blah"); break; } case AttributeTypeCode.Money: { entity.SetField(field, new Money(1)); break; } case AttributeTypeCode.Owner: { entity.SetField(field, new EntityReference("systemuser", CurrentUserId)); break; } case AttributeTypeCode.PartyList: { entity.AddActivityParty(field, "systemuser", CurrentUserId); break; } case AttributeTypeCode.Picklist: { entity.SetField(field, new OptionSetValue(XrmService.GetOptions(field, type).First().Key)); break; } case AttributeTypeCode.State: { break; } case AttributeTypeCode.Status: { break; } case AttributeTypeCode.String: { entity.SetField(field, "1234"); break; } case AttributeTypeCode.Uniqueidentifier: { break; } case AttributeTypeCode.Virtual: { break; } } }