protected Entity CreateAccount() { var entity = new Entity("account"); var maxNameLength = XrmService.GetMaxLength("name", "account"); entity.SetField("name", "Test Account - " + DateTime.Now.ToLocalTime()); entity.SetField("fax", "0999999999fax"); entity.SetField("telephone1", "0999999999"); entity.SetField("emailaddress1", "*****@*****.**"); if (entity.GetField("address1_line1") == null) { entity.SetField("address1_line1", "100 Collins St"); entity.SetField("address1_city", "Melbourne"); entity.SetField("address1_stateorprovince", "VIC"); entity.SetField("address1_postalcode", "3000"); } Entity contact = null; if (entity.GetField("primarycontactid") == null) { contact = CreateContact(null); entity.SetLookupField("primarycontactid", contact); } var account = CreateAndRetrieve(entity); if (contact != null) { contact.SetLookupField("parentcustomerid", account); UpdateFieldsAndRetreive(contact, new[] { "parentcustomerid" }); } return(account); }
protected Entity CreateAccount() { var entity = new Entity(Entities.account); var maxNameLength = XrmService.GetMaxLength(Fields.account_.name, Entities.account); entity.SetField(Fields.account_.name, "Test Account - " + DateTime.Now.ToLocalTime()); entity.SetField(Fields.account_.fax, "0999999999fax"); entity.SetField(Fields.account_.telephone1, "0999999999"); entity.SetField(Fields.account_.emailaddress1, "*****@*****.**"); entity.SetField(Fields.account_.address1_line1, "100 Collins St"); entity.SetField(Fields.account_.address1_city, "Melbourne"); entity.SetField(Fields.account_.address1_stateorprovince, "VIC"); entity.SetField(Fields.account_.address1_postalcode, "3000"); Entity contact = CreateContact(null); entity.SetLookupField(Fields.account_.primarycontactid, contact); var account = CreateAndRetrieve(entity); contact.SetLookupField(Fields.contact_.parentcustomerid, account); XrmService.Update(contact, new[] { Fields.contact_.parentcustomerid }); return(account); }
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)); }
public virtual Entity CreateAndRetrieve(Entity entity, XrmService xrmService = null) { if (xrmService == null) { xrmService = XrmService; } var primaryField = xrmService.GetPrimaryField(entity.LogicalName); if (!entity.Contains(primaryField)) { entity.SetField(primaryField, ("Test Scripted Record" + DateTime.UtcNow.ToFileTime()).Left(xrmService.GetMaxLength(primaryField, entity.LogicalName))); } if (entity.LogicalName == Entities.contact && !entity.Contains(Fields.contact_.firstname)) { entity.SetField(Fields.contact_.firstname, "Test"); } if (entity.LogicalName == Entities.lead && !entity.Contains(Fields.lead_.firstname)) { entity.SetField(Fields.lead_.firstname, "Test"); } var id = xrmService.Create(entity); return(xrmService.Retrieve(entity.LogicalName, id)); }