public virtual Entity CreateAndRetrieve(Entity entity, XrmService xrmService = null) { if (xrmService == null) { xrmService = XrmService; } var primaryField = xrmService.GetPrimaryNameField(entity.LogicalName); if (!entity.Contains(primaryField)) { entity.SetField(primaryField, ("Test Scripted Record" + DateTime.UtcNow.ToFileTime()).Left(xrmService.GetMaxLength(primaryField, entity.LogicalName))); } if (entity.LogicalName == "contact" && !entity.Contains("firstname")) { entity.SetField("firstname", "Test"); } if (entity.LogicalName == "lead" && !entity.Contains("firstname")) { entity.SetField("firstname", "Test"); } if (!entity.Contains("transactioncurrencyid") && xrmService.FieldExists("transactioncurrencyid", entity.LogicalName)) { entity.SetLookupField("transactioncurrencyid", TransactionCurrency); } return(xrmService.CreateAndRetreive(entity)); }